unity3d - Getting Information from a Collider to another method -
i have 3 game objects have trigger collider on them script called detectcollision.cs following code:
public void ontriggerenter(collider col) { string name = ""; name = col.gameobject.name; }
i pass name of object collides object method add names of collided object. example: place holder 1 collides gameobject called a, place holder 2 collides gameobject called b, place holder 3 collides gameobject called c ... send names of collided objects method add strings make word - abc.
any tips appreciated
im not sure question meant im assuming want call class method store strings im writing this
for need create class static instance
public class classtostoreinfo : monobehaviour { public static classtostoreinfo thisinstance; private string collisionline = ""; void start() { thisinstance = this; } public void addstringaftercollision(string value) { collisionline += value; } }
then call class static variable within collider function
public void ontriggerenter(collider col) { string name = ""; name = col.gameobject.name; classtostoreinfo.thisinstance.addstringaftercollision(name); }
you can call above class in script , keep reference of instead of using static variable class instance. hope helps.
Comments
Post a Comment