I'm making an infinite runner game and I'm trying to spawn obstacles, but all of them float far above the ground instead of being at the ground level.
This is the code on summoning the bears.
PlatformGenerator Class
if (Random.Range (0f, 100f) < randomEnemyThreshold)
{
GameObject newEnemy = enemyPool.GetPooledObject();
Vector3 enemyPosition = new Vector3 (0f, 0f, 0f);
newEnemy.transform.position = transform.position + enemyPosition;
newEnemy.transform.rotation = transform.rotation;
newEnemy.SetActive(true);
}
Ask me more about the game if you need more information.
Edit:
Here is the whole class.
The PlatformGenerator Class
using UnityEngine;
using System.Collections;
public class PlatformGenerator : MonoBehaviour {
public GameObject thePlatform;
public Transform generationPoint;
public float distanceBetween;
private float platformWidth;
public ObjectPooler theObjectPool;
public float randomEnemyThreshold;
public ObjectPooler enemyPool;
// Käytä alkuarvon alustamiseen
void Start () {
platformWidth = thePlatform.GetComponent<BoxCollider2D>().size.x;
}
// Päivitys tulee joka ruutu
void Update () {
if (transform.position.x < generationPoint.position.x)
{
transform.position = new Vector3 (transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
//Instantiate (thePlatform, transform.position, transform.rotation);
GameObject newPlatform = theObjectPool.GetPooledObject();
newPlatform.transform.position = transform.position;
newPlatform.transform.rotation = transform.rotation;
newPlatform.SetActive (true);
if (Random.Range (0f, 100f) < randomEnemyThreshold)
{
GameObject newEnemy = enemyPool.GetPooledObject();
Vector3 enemyPosition = new Vector3 (0f, 0.5f, 0f);
newEnemy.transform.position = transform.position + enemyPosition;
newEnemy.transform.rotation = transform.rotation;
newEnemy.SetActive(true);
}
}
}
}
