I am trying to make it so that an object appears after 5 seconds in c#. I have tried nearly everything and I cannot figure it out.
using UnityEngine;
using System.Collections;
public class Spawn_delayer : MonoBehaviour {
public GameObject north_wall;
void Foo ()
{
StartCoroutine (Begin ());
}
IEnumerator Begin ()
{
yield return new WaitForSeconds (3);
transform.position = new Vector3 (104, 0, 76);
print (transform.position.x);
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
this is the code i have but it doesn’t seem to work, please help.
using UnityEngine;
using System.Collections;
public class WaitingTest : MonoBehaviour {
public GameObject north_wall;
void Foo ()
{
StartCoroutine (Begin ());
}
IEnumerator Begin ()
{
yield return new WaitForSeconds (3);
transform.position = new Vector3 (104, 0, 76);
print (transform.position.x);
}
// Use this for initialization
void Start ()
{
Foo();
}
// Update is called once per frame
void Update ()
{
}
}
Also you want it to APPEAR but this only moves it. If want to create object you can Instantiate it or if you want it to be hidden and show after 5 seconds you can set it to enabled = false; and after 5 seconds enable it.
The fact that it moves rather than appears really does not matter to much to me as long as it serves the function that i need. thank you for the suggestion though
It will be less intensive if you just enable/disable the wall instead of moving it, but this might not impact your game, depending on what your trying to make.
However, moving it is much easier, as if you enable/disable it, you will need an outside script to do so, since the wall will be disabled, so will any scripts attached to it.
The game im working on now is only a demonstration so i am not worried about it being well optimized. Next time i am making a game i will remember your suggestion though