- Home /
Question by
$$anonymous$$ · Jun 30, 2013 at 09:33 AM ·
c#collisionvariablesaccess
How to access variables from another script on collision ?
Hi all! I`m making a game with spots and ai; bots have a script "Aibot" with a int variable "botNumber", and spots have script "Spot" with variable "botOnSpot". So i just need to know what number of bot is staying in the radius of collision of a spot. So how can i equate this two variables on collision? I tried to use gameObject.SendMessage, but this doesnt help. Thanks!
Comment
Best Answer
Answer by $$anonymous$$ · Jul 01, 2013 at 12:39 PM
Found information at http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html .
This is my solution :)
void OnCollisionEnter(Collision collision)
{
myName = collision.gameObject.GetComponent<ScriptName>().name;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613105159im_/https://answers.unity.com/themes/thub/images/avi.jpg)