Hi im working on a character animation / interaction with the environment. Im trying to spawn rocks of different sizes going from the ground to where the gravity direction is applied.
Im using c# for both of my scripts (character_movements_animation.cs & powerUp.cs)
My question is how to spawn objects around my character and not through it. Im using the code below:
/* Variables Declaration */
public GameObject rock_Small;
public GameObject rock_Medium;
public GameObject rock_Large;
private float posX, posY, posZ;
private bool checkPos = false;
//Use this for initialization
void Start() {
//Empty for now
}
// Update is called once per frame
void Update() {
if (Random.Range(0, 100) < 10) {
checkPos = false;
posX = this.transform.position.x + Random.Range(-5.0f, 5.0f);
posY = this.transform.position.y;
posZ = this.transform.position.z + Random.Range(-5.0f, 5.0f);
if(posX > 3f && posY > 3f){
checkPos = true;
}
if (checkPos == true) {
Vector3 newPos = new Vector3(posX, posY, posZ);
Instantiate(rock_Small, newPos, rock_Small.transform.rotation);
}
}
}