Question by
SQUARE-BADGER · Sep 06, 2016 at 01:34 PM ·
scripting problemobjectbeginnervariables
scripting problems please help
hi, can i set the zombie variable from this script to be set as a object from within the scene in code, i tried a lot of codes no one realy worked using UnityEngine; using System.Collections;
public class SpawnScript : MonoBehaviour {
public int zombieamount = 4;
public GameObject zombie;
// Use this for initialization
void Start () {
Instantiate(zombie, transform.position, transform.rotation);
}
// Update is called once per frame
void Update () {
if (zombieamount <= 0)
{
Instantiate(zombie, transform.position, transform.rotation);
zombieamount = 4;
}
}
public void Zombiecount()
{
zombieamount -= 1;
}
}
Comment
Yes. If the zombie has a unique name you can do
zombie = GameObject.Find("ZombieInScene");
You could also find the zombie by tag
GameObject.FindWithTag("ZombieTag");
, assign it directly in the inspector by creating another public variable in your class,