x


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?

more ▼

asked Sep 08 '11 at 05:13 AM

sam32x gravatar image

sam32x
178 38 55 62

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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)

more ▼

answered Sep 08 '11 at 05:24 AM

andrew gravatar image

andrew
549 10 12 18

BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'.

Sep 08 '11 at 05:35 AM sam32x

transform has a lowercase t.

Sep 08 '11 at 05:57 AM andrew

cool no errors now :D

Sep 08 '11 at 08:33 AM sam32x
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1950
x179
x57

asked: Sep 08 '11 at 05:13 AM

Seen: 645 times

Last Updated: Sep 08 '11 at 08:33 AM