- Home /
Question by
colijn · Sep 15, 2019 at 11:53 AM ·
instantiateprefabreplace
place Campfire(prefab) when i throw down 4 sticks
place Prefab(Campfire) when i throw down 3 sticks on the ground
i am working on this VR survival game and i want o be able to create a campfire when i throw 3 or 4 sticks and destroy the sticks and replace them with a campfire prefab
public gameobject Stick;
public prefab CampFire; //(don't know if this is correct)
oncollisonenter(colission collider)
{
if(collider.tag = Stick);
{
destroy(Stick)
Place Campfire();
}
void Place CampFire;
{
instantiate Campfire
}
but is doesn't work (my real code is correctly spelled) but still
i would really like all the info i can get
same thing with a folded tent prefab and when i throw it down it replaces with a unfolded tent prefab
Comment
Answer by muhashmed · Sep 15, 2019 at 04:13 PM
Try this (I wrote it in notepad and have not tested yet)
public GameObject Stick;
public GameObject[] Sticks;
public GameObject CampFire;
int countOfSticks = 0;
void OnCollisonEnter(Colission collider)
{
if(collider.gameObject.tag == Stick);
{
countOfSticks++;
Sticks[countOfSticks].gameObject = collider.gameObject;
PlaceCampFire();
}
}
void OnCollisonExit(Colission collider)
{
if(collider.gameObject.tag == Stick);
{
countOfSticks--;
}
}
void PlaceCampFire()
{
if(countOfSticks > 3)
{
Instantiate(CampFire);
try
{
foreach(gameObject obj in Sticks)
{
Destroy(obj);
}
}
catch
{
}
}
}
sorry bud it aint working out of the box i tweaked it a bit so it didnt get errors
where do i place it. on what object?