예제 #1
0
    // Use this for initialization
    void Start()
    {
        // random skin
        skin = skins[Mathf.FloorToInt(Random.Range(0, skins.Length))];
        GetComponent <MeshRenderer>().material = skin;

        a = gameObject.AddComponent <AudioSource>();

        // get component reference
        spawnerComponent = GetComponent <CatSpawner>();

        // get thought bubble reference
        thoughtBubble = transform.FindChild("ThoughtBubble").gameObject;
        // start hidden
        HideThoughtBubble();

        // set door
        door = GameObject.Find("Door").GetComponent <Door>();

        // calculate doormat location
        doormatLocation = door.transform.position - Vector3.right * 0.7f + Vector3.forward * 0.5f;
        //Debug.DrawLine(doormatLocation, Vector3.zero, Color.red, 10);

        // start with a cat
        GetCat();

        // immediately go to the door
        GoToDoor();

        // let the manager know that this person is next in line
        Manager.instance.personManager.Queue(this);
    }
예제 #2
0
    void OnTriggerEnter(Collider collider)
    {
        if (collider.CompareTag("NoSpawnZone"))
        {
            Debug.Log("This animal is in No Spawn Zone!");
            CatSpawner catSpawner = GetComponentInParent <CatSpawner>();

            catSpawner.totalSpawnedNumber--;

            Destroy(gameObject);
        }
    }
예제 #3
0
 void Awake()
 {
     source = GetComponent <AudioSource> ();
     if (instance == null)
     {
         DontDestroyOnLoad(this);
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
예제 #4
0
    private void Start()
    {
        _isWalking = true;

        _spawner = FindObjectOfType <CatSpawner>();

        _enterPoint = _spawner.EnterPoint();
        _exitPoint  = _spawner.ExitPoint();
        _walkPoints = _spawner.GetWaypoints();

        _transform = GetComponent <Transform>();

        WalkToPoint(_enterPoint);
        StartCoroutine(Walking());
    }
예제 #5
0
 private void Start()
 {
     _catSpawner = FindObjectOfType <CatSpawner>();
 }
예제 #6
0
    private void FixedUpdate()
    {
        if (!phaseActive)
        {
            return;
        }

        placeDelay       -= Time.fixedDeltaTime;
        placeDelay        = Mathf.Max(0, placeDelay);
        moneyDisplay.text = "$" + money;
        if (money < 8)
        {
            countdown.enabled = true;
            countdown.text    = "READY\n" + Mathf.Ceil(countdownTimer);
            countdownTimer   -= Time.fixedDeltaTime;
            if (countdownTimer <= 0)
            {
                DeactivateTowerPhase();
            }
        }
        else if (placeDelay == 0)
        {
            bool       selecting = false;
            Ray        ray       = new Ray(transform.position, Vector3.down);
            RaycastHit rayhit;
            if (Physics.SphereCast(ray, .7f, out rayhit, 100, castMask))
            {
                selecting = true;
                CatSpawner spawner = rayhit.collider.gameObject.GetComponent <CatSpawner>();
                Tower      tower   = rayhit.collider.gameObject.GetComponentInChildren <Tower>();
                if (spawner != null)
                {
                    selectionText.text = "Cat crate. Cats will spawn here!";
                }
                else if (tower != null)
                {
                    if (tower.upgraded)
                    {
                        selectionText.text = "X";
                    }
                    else
                    {
                        selectionText.text = "Upgrade $12";
                        if (money >= 12)
                        {
                            if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Jump"))
                            {
                                //upgrade tower
                                money -= 12;
                                GameObject upTower = GameObject.Instantiate(largetowerPrefab);
                                upTower.transform.position = rayhit.collider.gameObject.transform.position;
                                upTower.transform.rotation = rayhit.collider.gameObject.transform.rotation;
                                Destroy(rayhit.collider.gameObject);
                                placeDelay = .05f;
                            }
                        }
                    }
                }
                else if (rayhit.collider.gameObject.layer == 12)
                {
                    selectionText.text = "Build tower $8";
                    if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Jump"))
                    {
                        money -= 8;
                        GameObject placedTower = GameObject.Instantiate(smalltowerPrefab);
                        placedTower.transform.position = rayhit.point;
                        placedTower.transform.rotation = Quaternion.Euler(0, Random.value * 360, 0);
                        placeDelay = .05f;
                    }
                }
                else
                {
                    selecting          = false;
                    selectionText.text = "X";
                }
            }
            else
            {
                selectionText.text = "X";
            }

            if (selecting)
            {
                transform.position += Time.fixedDeltaTime * slowMoveSpeed * new Vector3(-Input.GetAxis("Vertical"), 0, Input.GetAxis("Horizontal"));
            }
            else
            {
                transform.position += Time.fixedDeltaTime * fastMoveSpeed * new Vector3(-Input.GetAxis("Vertical"), 0, Input.GetAxis("Horizontal"));
            }
            transform.position = new Vector3(Mathf.Clamp(transform.position.x, -maxMove, maxMove), transform.position.y, Mathf.Clamp(transform.position.z, -maxMove, maxMove));
        }
    }
예제 #7
0
 private void Start()
 {
     _spawner         = FindObjectOfType <CatSpawner>();
     _slider.maxValue = _requiredTapsCount;
 }