Exemple #1
0
    private void Attack()
    {
        GameObject camera = transform.GetChild(0).gameObject;

        if (acquiredWeapons[currentWeapon].name == "Fireball" && !cooldownWait)
        {
            GameObject fireball = Instantiate(fireballProjectile, camera.transform.position + (camera.transform.forward), Quaternion.identity);
            acquiredWeapons[currentWeapon].SetActive(false);
            fireball.GetComponent <Rigidbody>().velocity = camera.transform.forward * 10;
            fireball.transform.right = -transform.forward;
            StartCoroutine(StartCooldown());
        }
        else if (currentAnim != null && !swingCooldownWait)
        {
            currentAnim.Play("Attack");

            Ray        ray = new Ray(camera.transform.position, camera.transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 2.65f))
            {
                Debug.DrawRay(hit.point, hit.normal, Color.yellow, 20.0f);
                SkullAttack skullScript = hit.transform.gameObject.GetComponent <SkullAttack>();
                if (skullScript != null)
                {
                    skullScript.TakeDamage();
                }
            }
            StartCoroutine(SwingCooldown());
        }
        else
        {
            return;
        }
    }
Exemple #2
0
    // Use this for initialization
    void OnEnable()
    {
        timer          = wanderTimer;
        player         = GameObject.FindGameObjectWithTag("Player");
        anim           = GetComponent <Animator>();
        m_GroundNormal = new Vector3(0, 1, 0);

        agent.updateRotation = false;
        agent.updatePosition = true;

        if (chaseEvent == null)
        {
            chaseEvent = new UnityEvent();
        }

        attackScript = GetComponent <SkullAttack>();

        chaseEvent.AddListener(attackScript.OnStartChase);
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        if (LevelEnd == null)
        {
            LevelEnd = new UnityEvent();
        }

        if (GameOver == null)
        {
            GameOver = new UnityEvent();
        }

        if (uiManager == null)
        {
            uiManager = GetComponent <UIManager>();
        }

        LevelEnd.AddListener(uiManager.OnLevelEnd);
        LevelEnd.AddListener(AddLevelCount);
        player   = GameObject.FindGameObjectWithTag("Player");
        endLight = GameObject.Find("End Light");
        GameObject[] monsterObjects = GameObject.FindGameObjectsWithTag("Monster");
        for (int i = 0; i < monsterObjects.Length; i++)
        {
            WanderingAI   aiScript     = monsterObjects[i].GetComponent <WanderingAI>();
            MonsterAttack attackScript = monsterObjects[i].GetComponent <MonsterAttack>();
            GameOver.AddListener(aiScript.PlayerIsDead);
            GameOver.AddListener(attackScript.PlayerIsDead);
            LevelEnd.AddListener(aiScript.PlayerIsDead);
            LevelEnd.AddListener(attackScript.PlayerIsDead);
        }
        GameObject[] skullObjects = GameObject.FindGameObjectsWithTag("Skull");
        for (int i = 0; i < skullObjects.Length; i++)
        {
            SkullMove   aiScript     = skullObjects[i].GetComponent <SkullMove>();
            SkullAttack attackScript = skullObjects[i].GetComponent <SkullAttack>();
            GameOver.AddListener(aiScript.PlayerIsDead);
            GameOver.AddListener(attackScript.PlayerIsDead);
            LevelEnd.AddListener(aiScript.PlayerIsDead);
            LevelEnd.AddListener(attackScript.PlayerIsDead);
        }
        GameObject[] ratObjects = GameObject.FindGameObjectsWithTag("Rat");
        for (int i = 0; i < ratObjects.Length; i++)
        {
            RatMove   aiScript     = ratObjects[i].GetComponent <RatMove>();
            RatAttack attackScript = ratObjects[i].GetComponent <RatAttack>();
            GameOver.AddListener(aiScript.PlayerIsDead);
            GameOver.AddListener(attackScript.PlayerIsDead);
            LevelEnd.AddListener(aiScript.PlayerIsDead);
            LevelEnd.AddListener(attackScript.PlayerIsDead);
        }

        GameOver.AddListener(uiManager.OnGameOver);
        GameOver.AddListener(GetComponent <ScreenFader>().OnGameOver);
    }