- Home /
IPad Access 3D Object Variable with Raycast
Hi
I have 2 cubes and i would them to change colors when you touch them If you touch the cube once, it changes a value of that object to tru, if you touch it again changes to false etc...
I am having problems accessing that value, i commented the line where I need the help
Thanks!
var switchOn : System.Boolean = false;
private var hit : RaycastHit; private var ray : Ray;//ray we create when we touch the screen
function FixedUpdate () {
if(Input.touchCount == 1) {
ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
Debug.DrawLine(ray.origin,ray.direction * 10);
if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
if(hit.transform.name == "Box01"){
if(theClipPlaying == false){
//This is where I need help, to alter value of object
hit.transform.name.switchOn = true;
}
else{
//This is where I need help, to alter value of object
hit.transform.name.switchOn = false;
}
}
}
}
}
Your answer
Follow this Question
Related Questions
[C#] 3D raycast to sprite. Two cameras. 1 Answer
Raycast not hitting the collider properly it always has a weird offset 0 Answers
,How to lock the raycast on the first point hit? 2 Answers
Cube clips and falls through wall when held 0 Answers
Quarternion.LookRotation is only rotating my game object on one axis 1 Answer