I am having problems with code I am writing that applies particles to objects hit by my projectile. Everything but the parenting works fine, the clone is created but is stuck at the position it was instantiated at.
Getting
NullReferenceException: Object reference not set to an instance of an object
ProjectileScript.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/Player/ProjectileScript.cs:32)
Heres the script:
using UnityEngine;
using System.Collections;
public class ProjectileScript : MonoBehaviour {
public bool isClone = false;
public GameObject myParticle;
void Start () {
}
// Update is called once per frame
void Update () {
if(isClone == true){
renderer.enabled = true;
Destroy (gameObject, 5);
}
}
void OnCollisionEnter(Collision other){
if(isClone == true){
if(other.gameObject.tag != "Ground"){
if(other.gameObject.tag == "Enemy"){
Transform clone;
clone = Instantiate(myParticle, other.transform.position, other.transform.rotation) as Transform;
clone.transform.parent = other.transform;
}
Destroy (gameObject);
}
}
}
}