- Home /
Question by
sam32x · Sep 08, 2011 at 05:13 AM ·
raycastingsomething
raycasting help
okey so i found a random script for raycasting
var damage : float = 1;
function Update(){
if(Input.GetButtonDown("Fire1")){
FireOneShot();
}
}
function FireOneShot(){
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast (localOffset, direction, hit, 300)) {
Debug.DrawLine (localOffset, hit.point, Color.cyan);
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
it keeps saying unknown identifier "localoffset" so like what should it be?
Comment
Best Answer
Answer by andrew · Sep 08, 2011 at 05:24 AM
Assuming you want the origin of the ray to be the game object this script is attached to, then it should just be a matter of replacing localOffset with transform.position (twice)
BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Raycasting, For Tire Effect, Glitching at HighSpeeds! 1 Answer
UnityEngine.Input.GetMouseButton(1)) issue 1 Answer
how to update 2 Answers
How To Move Object To Terrain Slope in C# With Raycast? 2 Answers