Hi, I’m trying to have prefab music notes come out of my guitar melee weapon and it’s working. I’d like the notes to be destroyed after a few seconds, but they stay in the scene.
I tried adding a destroy game object line in the java melee script after instantiation of the musicnote, but it only destroyed the guitar.
Then I tried adding a destroy gameobject script, this time in C# to the prefab musicnote.
No errors popped up but the musicnote clones just keep coming and none get destroyed. Any feedback on what I’m doing wrong would be great.
#pragma strict
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var Mockron_Guitar : Transform;
var MusicNote : GameObject;
function Update()
{
if (Input.GetButtonDown("Fire1"))
{
animation.Play ("Melee");
}
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
var instance : GameObject = Instantiate(MusicNote, transform.position, transform.rotation);
}
}
}
using UnityEngine;
using System.Collections;
public class Destroy : MonoBehaviour {
GameObject MusicNote;
// Update is called once per frame
void Start () {
Destroy (gameObject);
}
}