Use of SendMessage function in Unity3D

Advertisemen

Let's say want cube to jump when you push the button.
Just for the demonstration purpose create two cubes in Unity and name one of as button. Then, create two scripts called - classA and classB. Attach classA in the button cube and classB in another cube. And type the followings in classA and classB -
classA script -


It sends message to the referenced cube saying execute "JumpCube" function OnMouseDown with the speed of 400. DontRequireReceiver means if it can't find "JumpCube" function in the another cube, no error will be called in unity.

classB script -

Now, make sure you have attached rigid body in the cube with classB script and drag this cube onto classA's cube reference point. like this -


Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D