Question by
Unalll · Jun 24, 2020 at 08:12 PM ·
c#gameobjectinitializationinitializeroads
How can I let spawn gameobjects on a road?? I need urgently a help!!! Please!
Also ich möchte, dass ein Objekt (Kiste) sich auf dem Road spawnt. Aber diesen Road habe ich als Instantiate erstellt sodass sich immer wieder von alleine dupliziert.
public GameObject roadPrefab;
public float offset = 0.707f;
public Vector3 lastPos;
public void StartBuilding()
{
InvokeRepeating("CreateNewRoadPart", 1f, .5f);
}
public void CreateNewRoadPart()
{
UnityEngine.Debug.Log("Create new Road part");
Vector3 spawnPos = Vector3.zero;
float chance = UnityEngine.Random.Range(0, 100);
if (chance < 50)
spawnPos = new Vector3(lastPos.x + offset, lastPos.y, lastPos.z + offset)
else
spawnPos = new Vector3(lastPos.x - offset, lastPos.y, lastPos.z + offset);
GameObject g = Instantiate(roadPrefab, spawnPos, Quaternion.Euler(0,45,0));
lastPos = g.transform.position;
roadCount++;
if(roadCount % 4 == 0)
{
g.transform.GetChild(0).gameObject.SetActive(true);
}
}
private void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
CreateNewRoadPart();
}
}
So sieht der Code aus, die für die automatische erweiterung von Road zuständig ist. Aber wie kann ich nun Hindernisse auf dem Road bauen damit sich diese automatisch auf dem Road erscheint?
Bitte ich brauche dringend hilfe!!
Comment
Your answer
Follow this Question
Related Questions
inheritance - using base class member variables 2 Answers
How can I change GameObject's texture? 1 Answer
How to find GameObject in script? 1 Answer
My code has some invalid arguments 1 Answer
joystick android 3d , help. 0 Answers