0
\$\begingroup\$

Hi again you fine folks.

So I'm making a driving game and there is going to be some cows in the road you have to dodge.

Currently I've laid 3 spawnpoints in the form of flat cubes, with the following script attached to each of them. (The reason I am manually laying the spawn points out myself is that the road is very windy, and has steep hills etc , and I was struggling to find a way to prodecurally place them on the road exactly at correct height etc.

Here is the code im using for these spawn points. For some reason I am getting all 3 cows spawn on the first spawn point, instead of just one. I haven't driven the car thru to the other 2 spawn points, id guess there'd be 3 cows at each of them. (I have to actually build to my phone to get that far due to the controls being for mobile not PC):

public class CowSpawn : MonoBehaviour {
public GameObject bullPrefab;
public float spawnChance;
bool willSpawn = false;

private GameObject bull;

// Use this for initialization
void Start()
{
    if (Random.value < spawnChance)
    {
        willSpawn = true;
    }

    bull = (GameObject)Instantiate(bullPrefab);
    bull.transform.position = GetComponent<GameObject>().transform.position;


}

// Update is called once per frame
void Update () {

}

}

\$\endgroup\$

1 Answer 1

-1
\$\begingroup\$

No, sorry I have just found the answer. I am trying to access a GameObject that doesnt exist. I just needed to remove GetComponent() completely, as I was already 'in' that GameObject with that script

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Exactly ;) please Accept your own answer so people know your question is already answered \$\endgroup\$
    – derHugo
    Jul 20, 2017 at 16:48
  • \$\begingroup\$ Hi Hugo, yes I would like to but it told me to wait two days. I still have 1 day to wait :/ sorry about that. Meanwhile, dont spose you can look at this problem, probably easy for experience programmers :) gamedev.stackexchange.com/questions/145042/… thanks \$\endgroup\$ Jul 20, 2017 at 16:50
  • \$\begingroup\$ Ha okey ... That's silly somehow so ^^ \$\endgroup\$
    – derHugo
    Jul 20, 2017 at 16:51
  • \$\begingroup\$ yeah the 2 days wait is silly :] ... uh i hope my new question isnt too silly (or maybe i hope it is as should be easy to fix :)) ) \$\endgroup\$ Jul 20, 2017 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .