- Home /
Question by
alone1992 · Nov 30, 2013 at 08:57 AM ·
raycastfind-gameobject
what is the problem of my raycast object finder script?
hello I write this code for finding my objects and put them in variable to move them but I my code can't find any object in his sides
var up = transform.TransformDirection(Vector3.up);
var right = transform.TransformDirection(Vector3.right);
//====================================================|
var hit_up : RaycastHit;
var hit_down : RaycastHit;
var hit_right : RaycastHit;
var hit_left : RaycastHit;
//====================================================|
var UpObject : GameObject;
var DownObject : GameObject;
var RightObject : GameObject;
var LeftObject : GameObject;
//====================================================|
function Update () {
//UP
Debug.DrawRay(transform.position, Vector3.up * 0.25 , Color.blue);
Debug.DrawRay(transform.position, -Vector3.up * 0.25 , Color.green);
Debug.DrawRay(transform.position, Vector3.right * 0.25 , Color.gray);
Debug.DrawRay(transform.position, -Vector3.right * 0.25, Color.grey);
if(Physics.Raycast(transform.position, -up, hit_up, 0.3)){
UpObject = hit_up.collider.gameObject;
Debug.Log("up");
}
//Down
if(Physics.Raycast(transform.position, up, hit_down,0.3)){
Debug.Log("down");
DownObject = hit_down.collider.gameObject;
}
//Right
if(Physics.Raycast(transform.position, right, hit_right,0.32)){
RightObject = hit_right.collider.gameObject;
Debug.Log("right");
}
//Left
if(Physics.Raycast(transform.position, -right, hit_left,0.32)){
LeftObject = hit_left.collider.gameObject;
Debug.Log("left");
}
}
thanks
Comment
Best Answer
Answer by alone1992 · Nov 30, 2013 at 11:34 AM
the problem is in my two first line's they should go in Update function:
function Update () {
var up = transform.TransformDirection(Vector3.up);
var right = transform.TransformDirection(Vector3.right);
.
.
.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
physics2d.raycastall help please 1 Answer
Problems with Raycast 0 Answers
Custom Collision Detection 4 Answers
Simple (?) touch-command on iPhone 2 Answers