Tuesday, 15 January 2013

c# - Passing Value from OnTriggerEnter function -



c# - Passing Value from OnTriggerEnter function -

i trying pass on value ontriggerenter function class class.i set value want pass global variable.this how :

public gameobject go; public bool issomething; public static aclass instance; public void start() { instance=this; } public void ontriggerenter(collision other) { if(go.tag=="something") { issomething=true; } }

the problem @ class,i phone call issomething aclass , run unity,it give me nullexceptionreference when pass through game object.this class code :

private aclass aclass; public void start() { aclass=aclass.instance; } public void update() { debug.log(aclass.issomething); //<-----------------this give null exception reference }

i want value after pass collider trigger , not before passing collider trigger.i don't know dumb question hope can give me idea.thanks. :)

try assigning instance in awake function:

public void awake() { instance = this; }

there's no guarantee start() function of 1 object happens before or after of object unless explicitly set execution order.

c# unity3d

No comments:

Post a Comment