How do I send something over the network in Javascript?
Options
I have only just begun using PUN and yes I understand C# is ideal but right now I am using JavaScript. I was hoping you would be able to tell me why my code isn't sending the message to the object I need to be destroyed. I know it is almost 100% going to be wrong but I hope you will be able to help as I have looked online for hours and can't find anything.
This is the script on the object that shoots the cube.
This is the code on the cube
This is the script on the object that shoots the cube.
function Update(){
if(Input.GetMouseButton(0)){
var hit : RaycastHit;
var fwd : Vector3 = transform.TransformDirection(Vector3.back);
Debug.DrawRay(transform.position, fwd, Color.green);
GetComponent.<Animation>().Play("ResponseShoot");
if(Physics.Raycast(transform.position, fwd,hit, 300))
{
if(hit.transform.CompareTag("Destroy")){
destroyScript = hit.transform.GetComponent("Destroy");
destroyScript.photonView.RPC("TakeDamage", RPCMode.All, 100);
}
}
}
}
This is the code on the cube
public var health = 100;
@PunRPC
function TakeDamage(amount){
health -= amount;
Debug.Log("DAMAGE");
if(health <= 0){
Destroy(this.gameObject);
}
}
0
Best Answer
-
This works: camDead.GetComponent(PhotonView).RPC("Spawn", PhotonTargets.All);5
Answers
-
We can't test the code for you but it does look OK.
Is there anything in the console / log for the sender or receiver? Are you sure you are calling .RPC()? And your client is in a room with someone else?0 -
This works: camDead.GetComponent(PhotonView).RPC("Spawn", PhotonTargets.All);5