|
How could i click a cube and have it because the variable target. I would like to have this in C# so if that is possible please give it to me like that I saw this post which is practically what i need but i got errors converting it because it was in javascript http://answers.unity3d.com/questions/199159/how-to-make-an-object-the-target-when-you-click-on.html The main problem im getting is the variable ray in that post This is the script in that post What type of variable is that?
(comments are locked)
|
|
This is the C# version:
RaycastHit hit;
Ray ray;
Transform target;
void Update (){
if (Input.GetMouseButtonDown(0)){
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, out hit, 100)){
if (hit.transform.tag == "TagName"){
target = hit.transform;
}
}
}
}
Thanks but a couple of questions... I get this semi error... I still can run my script but this pops up NullReferenceException UnityEngine.Camera.ScreenPointToRay (Vector3 position) Control.Update () (at Assets/MyAssets/Scripts/Control.cs:32) And The variable target doesn't actually take that object i click as the variable
Jan 02 '12 at 02:45 AM
CursedScripter
(comments are locked)
|

The variable ray is the variable im talking about at the end