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);
}
}