Tuesday, December 9, 2014

Unity3D access other object script variable and function

Okay, let say you have 2 object, cube1 and plane1

then let say cube1 have cube1script.js and plane 1 have plane1script.js

let say plane1script.js have variable lala:int and function lolo()

let say your cube1 script want to access plane1 script variable or function

below is how you do it

inside your cube1script.js
==================
var haha : Transform; (you drag your plane1 object into here on outside)

haha.GetComponent(plane1script).lala =1;      //here you can modify the variable in plane1

haha.GetComponent(plane1script).lolo();   //here you can call the function of plane1








No comments:

Post a Comment