Hello,
I checked other questions and I don’t understand why I receive this common error.
Here are the important parts of the code :
public static GameObject particle;
public static GameObject clickedGmObj;
public static GameObject damagePrefab;
public static GameObject healPrefab;
......
void Update () {
GameObject clickedGmObj = null;
if(Input.GetMouseButtonDown(0))
{
clickedGmObj = GetClickedGameObject();
......
GameObject GetClickedGameObject()
{
Ray ray = UICamera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out hit))
{
return hit.transform.gameObject;
}
else
{
return null;
}
}
.......
public void TeamCast()
{
var bounds = hit.collider.bounds;
var v3 = bounds.center;
v3.y -= bounds.extents.y;
damagePrefab = Instantiate(particle, v3, transform.rotation) as GameObject;
damagePrefab.transform.parent = clickedGmObj;
And here there are all the lines / functions dealing with spawning gameobjects, saving them or altering them.
Why it gives me the error for the line :
damagePrefab.transform.parent = clickedGmObj;
What I want to achieve is attach the spawned particles to the detected collider in the game which is a unit, so the particle effect will follow my unit around.
Thanks