- Home /
After picking up an object, spawn a new one in a random location
I'm currently working on a game that has my player picking up items that then follow the player. So far the following and picking up works, but I can't seem to make it spawn a new one.
using UnityEngine;
using System.Collections;
public class Pickery : MonoBehaviour {
public static float Counter = 0.0f;
public GameObject parson;
public int Timekeeper = 10;
public GameObject cameran;
void OnTriggerEnter (Collider other){
Counter += 100f;
Debug.Log ("Counter");
cameran.SendMessage("Plus", Timekeeper);
parson.transform.parent = transform;
parson.transform.localPosition = new Vector3(0, 0, -1);
Instantiate(parson, Vector3(Random.Range(10,-35),921,Random.Range(267,310)), Quaternion.identity);
}
}
Any help would be appreciated.
What is not really working ? Do you have a compiling error ? Or nothing is instantiated ?
error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Do you know the line that generates the error ? If it is the Instantiate method, maybe you should declare parson as a Transform, not a GameObject.
Doing that seems to get me this error, on both the line of code that declares parson and the one that instantiates a new one:
Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
Answer by Msurdej · Nov 11, 2012 at 09:37 PM
Question was answered needed to put
`parson = Instantiate(parson, new Vector3(Random.Range(10,-35),921,Random.Range(267,310)), Quaternion.identity)as GameObject;`
as the code instead of what I had. Thank you Kmulla and KiraSensei for your help.