Trying to delete bullet clone after time ERRORS!

Basically, i’m trying to make a clone bullet (Named MuzzleFlash(Clone) delete after a second or two. However i do get a error saying

BCE0018: The name 'gameObject.name' does not denote a valid type ('not found'). 

The Code is

var lifetime = 2.0f;
     
     function Awake ()
     {
var bulletOBJ : gameObject.name = ("MuzzleFlash(Clone)"); 
         Destroy(bulletOBJ, lifetime);
     }

Please be nice as i am new to Unity Coding.

just add something like this to your bullet prefab -

using UnityEngine;
using System.Collections;

public class Done_DestroyByTime : MonoBehaviour
{
	public float lifetime;

	void Start ()
	{
		Destroy (gameObject, lifetime);
	}
}

Set the time you want it to wait before destruct in your inspector.

:wink:

In UnityScript, declarations are of the form var variableName : VariableType.

In your case, var bulletOBJ : gameObject.name is being interpreted as declare a variable with the name as “bulletOBJ” and type as “gameObject.name”. “gameObject.name” is an invalid type (as the compilation error message points out).

The correct form would be:

function Awake ()
{
    var bulletObj:GameObject = GameObject.Find("MuzzleFlash(Clone)");
    Destroy(bulletOBJ, lifetime);
}