Hi
I have an object in middle of two another objects the object (in the middle) is moving and should stop when receive to others!!
I write this code but when I use that it isn’t work and when I remove the second part It work but just for one side!!
I think problem is in the var hit : raycasting !!?
var hSliderValue:int = 2;
var MovingSpeed : int = 2;
function Update () {
var hit : RaycastHit;
var right = -transform.TransformDirection(Vector3.forward);
var left = transform.TransformDirection(Vector3.forward);
transform.Rotate(0,0,Input.GetAxis("Mouse X")*hSliderValue);
transform.Translate(0,0,Input.GetAxis("Vertical")*MovingSpeed*Time.deltaTime);
//Compute the Right hand side
Debug.DrawRay(transform.position , right * 0.025 , Color.green);
if(Physics.Raycast(transform.position, right, hit, 0.025)){
if(hit.collider.gameObject.name == "right" Input.GetAxis("Vertical")<0 ){
MovingSpeed = 0;
}
else {
MovingSpeed = 2;
}
}
//Compute the left hand side
Debug.DrawRay(transform.position , left * 0.25 , Color.red);
if(Physics.Raycast(transform.position, left, hit, 0.25)){
if(hit.collider.gameObject.name == "left" Input.GetAxis("Vertical")>0 ){
MovingSpeed = 0;
}
else {
MovingSpeed = 2;
}
}
}
excuse me for my weak English.