Hi, I have this code here (please consider I’m new to C#)
using UnityEngine;
using System.Collections;
public class cloneAndDestroy : MonoBehaviour {
private UdpReceive udpRec;
//Object to be instantiated
Transform prefabToSpawn;
//One can only create 3 waypoints at a time
int maxAmt = 3;
// circular list: private
Transform[] maxAmtList;
private int curPos = 0;
void Start (){
Application.runInBackground = true;
//using find //
udpRec = GameObject.Find("OSC receiver").GetComponent(typeof(UdpReceive)) as UdpReceive;
maxAmtList = new Transform[maxAmt];
}
void Update (){
if (udpRec.maxValues.Length <= 0) {
return;
}
float cloneYes = udpRec.MaxValue(3);
if (cloneYes == 1){
if (maxAmtList[curPos]){
// if some object already in curPos...
Destroy(maxAmtList[curPos].gameObject); // delete it
}
//create a new waypoint and store it in curPos:
maxAmtList[curPos] = Instantiate(prefabToSpawn, transform.position, Quaternion.identity);
//increment curPos in a circular fashion:
curPos = (curPos + 1) % maxAmt; }
}
}
I get this error: error CS0266: Cannot implicitly convert type UnityEngine.Object' to
UnityEngine.Transform’. An explicit conversion exists (are you missing a cast?)
the line where the error seems to occur is: maxAmtList[curPos] = Instantiate(prefabToSpawn, transform.position, Quaternion.identity);
any idea why/ what should i do for solve this?
thanks!!!