- Home /
send message object variable
Hello, I am trying to send a variable with an object (var del = this.Gameobject;) to another script.
What I have is: var hitPoints : float = 50.0; var sound : AudioClip; var del = this.Gameobject;
function OnTriggerEnter (other : Collider) {
if (other.CompareTag ("Player")){
other.SendMessageUpwards("Medic", hitPoints, SendMessageOptions.DontRequireReceiver);
other.SendMessageUpwards("Del", del, SendMessageOptions.DontRequireReceiver);
AudioSource.PlayClipAtPoint(sound, transform.position);
//Destroy(gameObject);
//PhotonNetwork.Destroy(this.gameobject);
}
}
for sending the message, and:
public void Medic (float hitPoints) {
currentHp+=150;
if (currentHp > 250.0)
currentHp=250;
//PhotonNetwork.Destroy(other);
}
public void Del (GameObject del) {
PhotonNetwork.Destroy(del);
}
for receiving The problem is I get this error when running the game:
Failed to call function Del of class PlayerDamage Calling function Del with no parameters but the function requires 1. UnityEngine.Component:SendMessageUpwards(String, Object, SendMessageOptions) Medic:OnTriggerEnter(Collider) (at Assets/Resources/NewScripts/Medic.js:8)
You probably already saw the first script is js and the second c# public void Medic does work correctly, only the Del void gets an error
It would be great if someone could help me
Answer by Maerig · May 12, 2014 at 01:55 AM
GameObject
: The GameObject class.
gameObject
: The gameObject your script is attached to.
You have to use
var del = this.gameobject;
Your answer
![](https://koobas.hobune.stream/wayback/20220613144753im_/https://answers.unity.com/themes/thub/images/avi.jpg)