hi, i just want to try somthing simple, which is if i click a 3D cube for it to print somthing. can anyone write me a short line of code so i can learn from it? thanks
If you have a cube in your scene, you want to check out ScreenPointToRay and Raycasting in the scripting reference. heres the basic thing you want to do in pseudo code. Cast ray into scene. Ray emits from Mouse.Position if(ray hit == cube (this could be a tag, or by gameObject name) {print ("woot")}
thanks man, so i would do this in the function update? so: function Update () { if(ray hit == cube) {print ("woot")}} thanks
or in a collision function ? function OnCollision(collide : Hit) { function Update () { if(ray hit == cube) {print ("woot")}} ?? im not so good with this
you could also attach a script to the cube and use the OnMouseDown function, but that depends on your use-case example: function OnMouseDown() { print("woot"); }