Closed sakibguy closed 2 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroundGenerator : MonoBehaviour
{
public Transform groundPoint;
public ObjectPooler[] groundPoolers;
private float[] groundWidths;
// Start is called before the first frame update
void Start()
{
groundWidths = new float[groundPoolers.Length];
for(int i = 0; i < groundPoolers.Length; i++)
{
groundWidths[i] = groundPoolers[i].pooledObject.GetComponent<BoxCollider2D>().size.x;
}
}
// Update is called once per frame
void Update()
{
if(transform.position.x < groundPoint.position.x)
{
int random = Random.Range(0, groundPoolers.Length);
float distance = groundWidths[random]/2;
transform.position = new Vector3 (
transform.position.x + distance,
transform.position.y,
transform.position.z
);
GameObject ground = groundPoolers[random].GetPooledGameObject();
ground.transform.position = transform.position;
ground.SetActive(true);
transform.position = new Vector3 (
transform.position.x + distance,
transform.position.y,
transform.postion.z
);
}
}
}
https://answers.unity.com/questions/1751448/how-do-i-fix-this-22.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroundGenerator : MonoBehaviour
{
public Transform groundPoint;
public Camera fpsCam;
public ObjectPooler[] groundPoolers;
private float[] groundWidths;
// Start is called before the first frame update
void Start()
{
groundWidths = new float[groundPoolers.Length];
for(int i = 0; i < groundPoolers.Length; i++)
{
groundWidths[i] = groundPoolers[i].pooledObject.GetComponent<BoxCollider2D>().size.x;
}
}
// Update is called once per frame
void Update()
{
if(fpsCam.transform.position.x < groundPoint.position.x)
{
int random = Random.Range(0, groundPoolers.Length);
float distance = groundWidths[random]/2;
fpsCam.transform.position = new Vector3 (
fpsCam.transform.position.x + distance,
fpsCam.transform.position.y,
fpsCam.transform.position.z
);
GameObject ground = groundPoolers[random].GetPooledGameObject();
ground.transform.position = fpsCam.transform.position;
ground.SetActive(true);
fpsCam.transform.position = new Vector3 (
fpsCam.transform.position.x + distance,
fpsCam.transform.position.y,
fpsCam.transform.postion.z
);
}
}
}
fpsCam.transform.postion.z to fpsCam.transform.position.z
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GroundGenerator : MonoBehaviour { public Transform groundPoint; public Camera fpsCam; public ObjectPooler[] groundPoolers; private float[] groundWidths;
// Start is called before the first frame update
void Start()
{
groundWidths = new float[groundPoolers.Length];
for(int i = 0; i < groundPoolers.Length; i++)
{
groundWidths[i] = groundPoolers[i].pooledObject.GetComponent<BoxCollider2D>().size.x;
}
}
// Update is called once per frame
void Update()
{
if(fpsCam.transform.position.x < groundPoint.position.x)
{
int random = Random.Range(0, groundPoolers.Length);
float distance = groundWidths[random]/2;
fpsCam.transform.position = new Vector3 (
fpsCam.transform.position.x + distance,
fpsCam.transform.position.y,
fpsCam.transform.position.z
);
GameObject ground = groundPoolers[random].GetPooledGameObject();
ground.transform.position = fpsCam.transform.position;
ground.SetActive(true);
fpsCam.transform.position = new Vector3 (
fpsCam.transform.position.x + distance,
fpsCam.transform.position.y,
fpsCam.transform.position.z
);
}
}
}
Assets\Scripts\GroundGenerator.cs(42,15): error CS1061: 'Transform' does not contain a definition for 'postion' and no accessible extension method 'postion' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)