- Home /
how to call the script of an object being collided with a trigger2D
Hi, I am running in to a little trouble here. I am getting this error: error CS0176: Static member `localVariables.test()' cannot be accessed with an instance reference, qualify it with a type name instead
void OnTriggerStay2D (Collider2D other){ int num = other.gameObject.GetComponent("localVariables").index;//something is wrong here <<< }
i have an object called a(Clone), clone objects. when it is colliding with a trigger2D box, I want to get that objects int index, which is inside it's own script called localVariables.
public class localVariables : MonoBehaviour { public static int index; }
Am I calling the object correctly? What is wrong here?
Answer by Noob_Vulcan · May 29, 2014 at 06:28 AM
Make it public int index
. Remove static from index . Static members are called with Class Name not with class instance.
and change
other.gameObject.GetComponent<localVariables>().index
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Alternative collision detection methods? (c#) 1 Answer
Problem with using IEnumerator for method, c# 1 Answer
Do you have to set a object reference for every script? 0 Answers