- Home /
Question by
wacasce · Apr 14, 2021 at 09:26 AM ·
vector3instantiate prefab
Instatiating at different x Positions error
Hi guys. I have a slime container, which instantiates slimes depending on the random slime number generated in its script. The first slime is to be instantiated at the position of the sime container, the rest of the slimes are to be instantiated at a gradually increasing distance from the container.
Sometimes my script works, sometimes it doesnt ( spawns at the same position).
Can someone help me out, i think i have something wrong with my code below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bouncingSlimeSeed : MonoBehaviour
{
public GameObject [] bouncingSlimes;
Vector3 nextPos;
Transform slimePos;
Vector3 initialPos;
int howmanyDoubles;
public float xInc,yInc;
// Start is called before the first frame update
void Start()
{
initialPos = gameObject.transform.position;
howmanyDoubles = Random.Range(1,5);
slimePos = gameObject.transform;
createDoubles();
}
// Update is called once per frame
void Update()
{
}
void createDoubles(){
for(int i = 0; i < howmanyDoubles; i++){
Instantiate(bouncingSlimes[Random.Range(0,bouncingSlimes.Length)],
slimePos.position, Quaternion.identity);
slimePos.position += new Vector3(initialPos.x + xInc, initialPos.y + yInc, 0);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
My Raycast on awake fires and will not change Help! 0 Answers
Spawning prefabs in front of the player 1 Answer
Instantiate a 2D world question 2 Answers
Relative Rotation 1 Answer
Need some help with to grap .x with a Raycasthit (c#) 1 Answer