x


Errors on Bullet script

Hi I have done a script for a bullet by using documentation of unity but I have a couple of errors. Here you have the code:

// - instantiates a explosion prefab when hitting a surface
// - then destroys itself

var explosionPrefab : Transform;

function OnCollisionEnter(collision : Collision) {
        // Rotate the object so that the y-axis faces along the normal of the surface
        var contact : ContactPoint = collision.contacts[0];
        var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal);
        var pos : Vector3 = contact.point;


        // Kill ourselves
        Destroy(gameObject);
        SendMessage ("ApplyDamage", 1);
        clone =     Instantiate(explosionPrefab, pos, rot);

        // Destroy the projectile
        Destroy (gameObject);
}

And here you have the errors:

The referenced script on this Behaviour is missing!
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
ColisionBala:OnCollisionEnter(Collision) (at Assets/nuevo/ColisionBala.js:17)

And:

The referenced script on this Behaviour is missing!
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
$:MoveNext() (at Assets/nuevo/EnemyRangedAttack.js:170)

And:

SendMessage ApplyDamage has no receiver!
UnityEngine.Component:SendMessage(String, Object)
ColisionBala:OnCollisionEnter(Collision) (at Assets/nuevo/ColisionBala.js:16)

Anyone can help me? I achieve the explosion but the player don't loose life >__<'

Thanks for all

more ▼

asked May 09 '11 at 08:35 AM

Infinity gravatar image

Infinity
141 36 39 44

Don't you kill the same thing twice?

May 09 '11 at 10:27 AM Aldwoni

Don't know, can you help me?

May 09 '11 at 12:24 PM Infinity
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Only destroy the gameObject once as the last thing in your script.

Edit: You should also use

collider.gameObject.SendMessage ("ApplyDamage", 1);

instead of just SendMessage, since you want to call ApplyDamage to the player and not the bullet itself. The player also needs a to have a component attached with a function of the signature:

function ApplyDamage(var v : Integer){
}

And the player also need to have the collider object on the same GameObject as the script with the ApplyDamage function.

more ▼

answered May 09 '11 at 09:17 AM

Mortennobel gravatar image

Mortennobel
1.8k 10 15 34

Same problems with this. And when i wrote this post I forgot to write one of the errors (the one regarding to send message)

May 09 '11 at 12:27 PM Infinity
(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:

x308
x15
x3

asked: May 09 '11 at 08:35 AM

Seen: 891 times

Last Updated: May 09 '11 at 12:26 PM