- Home /
Select instantiated object with mouse
Hello,
Im having some problems with this script im working on to select an object, im getting an error saying: unknown identifier:'color'. and 'changeColorRed' is not a member of 'unityEngine.Transform'.
Im a started at scripting, so i belive maybe i am putting something in the wrong order that maybe could be the problem.
heres the script:
var selecaoMouse : Transform;
var ray : Ray = camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit;
Debug.DrawRay (ray.origin, ray.direction * 100, Color.yellow);
function changeColorRed()
{ selecaoMouse.renderer.material.color = color.red;
}
if (Physics.Raycast (ray.origin, ray.direction, hit, 100))
{
if(hit.collider.tag == "Object")
{
var object : GameObject = hit.collider.gameObject;
if(object != selecaoMouse) //new object selected
{
selecaoMouse.changeColorRed(); //unselect object
selecaoMouse = object;
}
}
}
im trying to figure out which is the problem with this script, i saw many examples of similar ones here on unity answers, but for some reason i couldnt make this work, i would appreciate some help on the subject
thanks for the attention
Vinicius Girotto
ViniGirotto, Just as your error message says, your function changeColorRed() is not a part of the definition of Transform.
Ins$$anonymous$$d of selecao$$anonymous$$ouse.changeColorRed();, you need to call changeColorRed();
However, it looks like your bigger problem is that you don't know how to program in JavaScript. There really is no shortcut around it - you need to spend some time reading up on how object oriented languages work.
Answer by ViniGirotto · Aug 18, 2011 at 04:25 PM
Thanks for the support, and indeed i dont know how to program in JavaScript, i mean, i am learning the syntax and the concepts while doing this project. There are some programming concepts that are still a bit cloudy to me yet, anyway thanks for the attention, i managed to make it work after yout tips, and ill keep on with the studies now.
Your answer
Follow this Question
Related Questions
C# mouse Raycast question 3 Answers
How to NOT select an object behind a GUI? 1 Answer
Move selected object. 1 Answer
Intersection point of mouse with ZX plane 1 Answer
how can i Find an object height, while click on that object? 1 Answer