void Awake()
    {
        StartCoroutine(OnGameStateChange(GameState));
        StartCoroutine(OnStartupDoneEvent());
        StartCoroutine(OnCocktailModes(selectedCocktailModes.Count));
        StartCoroutine(OnSequenceChangement(ModeSequenceType));
        StartCoroutine(OnEnvironementChromaChangement(environementChroma));

        SetupRewiredPlayers();

        ReInput.ControllerConnectedEvent    += (ControllerStatusChangedEventArgs obj) => UpdateGamepadList();
        ReInput.ControllerDisconnectedEvent += (ControllerStatusChangedEventArgs obj) => UpdateGamepadList();

        //OnPlaying += UpdateGamepadList;
        OnMenu += UpdateGamepadList;

        LoadModeManager.Instance.OnLevelUnloaded += UpdateGamepadList;

        OnPlaying     += () => SetMouseVisibility();
        OnRestartMode += () => SetMouseVisibility();
        OnPlaying     += UpdatePlayedModes;
        OnMenu        += () => Startup = StartupType.Wave;
        OnEndMode     += () => Startup = StartupType.Delayed;
        OnEnvironementChromaChange += SetPlayerMouseCursor;

        MenuManager.Instance.OnStartModeClick += UpdateGamepadList;
        MenuManager.Instance.OnStartModeClick += CreateAIs;

        SetPlayerMouseCursor();

        mainCamera         = GameObject.FindGameObjectWithTag("MainCamera");
        screenShakeCamera  = mainCamera.GetComponent <ScreenShakeCamera>();
        zoomCamera         = mainCamera.GetComponent <ZoomCamera>();
        dynamicCamera      = mainCamera.GetComponent <DynamicCamera>();
        menuCameraMovement = mainCamera.GetComponent <MenuCameraMovement>();
        slowMotionCamera   = mainCamera.GetComponent <SlowMotionCamera>();

        fixedDeltaTime   = Time.fixedDeltaTime;
        fixedDeltaFactor = 1 / fixedDeltaTime;

        GraphicsQualityManager.Instance.OnFixedDeltaTimeChange += (x) =>
        {
            fixedDeltaTime   = x;
            fixedDeltaFactor = 1 / fixedDeltaTime;
        };

        LoadEnvironementChroma();
    }
    // Update is called once per frame
    void Update()
    {
        if (fa.paused)
        {
            return;
        }
        if (FPSMainScript.FPSPlayer != null)
        {
            goal = FPSMainScript.FPSPlayer.transform.position;
        }
        //Close enough to attack?
        bool hit = false;

        if (square)
        {
            if (goal.x > transform.position.x - 1.2f &&
                goal.x < transform.position.x + 1.2f &&
                goal.z > transform.position.z - 1.2f &&
                goal.z < transform.position.z + 1.2f)
            {
                hit = true;
            }
        }
        else
        {
            if (Vector3.Distance(goal, transform.position) < 1f)            //cubes are normally 3 across
            {
                hit = true;
            }
        }


        if (hit)
        {
            if (fa.time > (zombieAttackTimeSet + zombieAttackDelay))
            {
                zombieAttackTimeSet = fa.time;
                HealthScript h = FPSMainScript.FPSPlayer.GetComponent <HealthScript>();
                h.health -= Random.Range(zombieMinDam, zombieMaxDam + 1);

                ScreenShakeCamera.Screenshake(0.5f, 0.3f, ScreenShakeCamera.ScreenshakeMethod.Basic);
            }
        }
    }
Exemple #3
0
        void Start()
        {
            for (int i = 0; i < effectInstancePools.Count; i++)
            {
                effectInstancePools [i].InstantiatePool(this);
            }

            //if the audio sources for effect audio groups are not set up they can have a default source
            //set up the groups to manage priority on which effects can interrupt eachother
            AudioSource groupNotSetUpSource = null;
            int         groups = System.Enum.GetValues(typeof(EffectAudioGroupType)).Length;

            for (int i = 0; i < groups; i++)
            {
                if (effectAudioSourceGroups.Count <= i)
                {
                    effectAudioSourceGroups.Add(new EffectAudioSourcePool());
                }
                if (effectAudioSourceGroups[i].pool == null)
                {
                    effectAudioSourceGroups [i].pool = new List <AudioSource> ();
                }
                if (effectAudioSourceGroups [i].pool.Count <= 0)
                {
                    if (groupNotSetUpSource == null)
                    {
                        if (logsOn)
                        {
                            Debug.Log("creating default effect AudioSource");
                        }
                        groupNotSetUpSource = new GameObject("defaultEffectAudioSource").AddComponent <AudioSource> ();
                        groupNotSetUpSource.transform.parent        = transform;
                        groupNotSetUpSource.transform.localPosition = Vector3.zero;
                    }
                    effectAudioSourceGroups [i].pool.Add(groupNotSetUpSource);
                }
            }

            screenShakeCamera = FindObjectOfType <ScreenShakeCamera> ();
        }
Exemple #4
0
    void Update()
    {
        if (fa.time >= (timeSet + delay))
        {
            switch (state)
            {
            case State.Prepping_MovingDown:
                iTween.MoveBy(this.gameObject, iTween.Hash("y", -verDist, "time", speedDown, "easetype", iTween.EaseType.easeInCirc));
                delay   = speedDown;
                timeSet = fa.time;
                state   = State.Prepping_WatingAtBottom;
                break;

            case State.Prepping_WatingAtBottom:
                delay   = pauseAtBottom;
                timeSet = fa.time;
                state   = State.Prepping_MovingUp;

                if (Setup.checkVecOnScreen(transform.position, false))
                {
                    ScreenShakeCamera.Screenshake(1, 0.15f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                    Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.RockImpact);
                }
                break;

            case State.Prepping_MovingUp:
                iTween.MoveBy(this.gameObject, iTween.Hash("y", verDist, "time", speedUp, "easetype", iTween.EaseType.easeInOutSine));
                delay   = speedUp;
                timeSet = fa.time;
                state   = State.Prepping_WaitingAtTop;
                break;

            case State.Prepping_WaitingAtTop:
                delay   = pauseAtTop;
                timeSet = fa.time;
                state   = State.Prepping_MovingDown;
                break;
            }
        }
    }
Exemple #5
0
    void Update()
    {
        if (fa.paused)
        {
            return;
        }
        if (!dead)
        {
            lastPos = transform.position;
            transform.Translate(0, 0, actualSpeed * fa.deltaTime);

            if (Vector3.Distance(FPSMainScript.playerPos, transform.position) < 1)
            {
                FPSMainScript.FPSPlayerScript.healthScript.health -= Random.Range(minDam, maxDam + 1);
                ScreenShakeCamera.Screenshake(0.2f, 0.1f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                GameObject go;
                go   = Instantiate(exploPrefab, hit.point, transform.rotation);
                dead = true;
                Destroy(this.gameObject);
            }

            ray.origin    = lastPos;
            ray.direction = transform.forward;
            float dist = Vector3.Distance(transform.position, lastPos);

            if (Physics.Raycast(ray, out hit, dist, mask))
            {
                dead = true;
                //Hit something!

                //Explode!
                GameObject go;
                go = Instantiate(exploPrefab, hit.point, transform.rotation);

                //destroy self
                Destroy(this.gameObject);
            }
        }
    }
    void Update()
    {
        if (infoScript.triggered == true)
        {
            infoScript.triggered = false;
            moving = true;
        }

        if (moving)
        {
            if (fa.time >= (timeSet + delay))
            {
                switch (state)
                {
                case State.Prepping_MovingDown:
                    iTween.MoveBy(this.gameObject, iTween.Hash("y", -verDist, "time", speedDown, "easetype", iTween.EaseType.easeInCirc));
                    delay   = speedDown;
                    timeSet = fa.time;
                    state   = State.Prepping_WatingAtBottom;
                    break;

                case State.Prepping_WatingAtBottom:
                    delay   = pauseAtBottom;
                    timeSet = fa.time;
                    state   = State.None;

                    if (Setup.checkVecOnScreen(transform.position, false))
                    {
                        ScreenShakeCamera.Screenshake(1, 0.95f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                        Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.RockImpact);
                    }
                    moving = false;
                    break;
                }
            }
        }
    }
    void Update()
    {
        if (fa.paused)
        {
            return;
        }
        //getting hit
        if (oldHealth != healthScript.health)
        {
            oldHealth = healthScript.health;
            //got hit

            iTween.PunchRotation(puppet, iTween.Hash("z", Random.Range(-45, 45), "time", Random.Range(0.3f, 0.5f), "easetype", iTween.EaseType.linear));
        }

        if (isHulk)
        {
            if (!hurt && healthScript.health <= FPSBalanceScript.FPSHulkHurtHP1)
            {
                hurt = true;
                meshRenderer.material = hurtMat;
            }
            if (!hurt2 && healthScript.health <= FPSBalanceScript.FPSHulkHurtHP2)
            {
                hurt2 = true;
                meshRenderer.material = hurtMat2;
            }
        }
        else
        {
            if (!hurt && healthScript.health <= FPSBalanceScript.FPSZombieHurtHP)
            {
                hurt = true;
                meshRenderer.material = hurtMat;
            }
        }

        if (healthScript.health <= 0)
        {
            GameObject ds = Instantiate(deathSound, transform.position, deathSound.transform.rotation);

            GameObject g1 = Instantiate(gib1Prefab, gib1Muzzle.transform.position, gib1Muzzle.transform.rotation);
            GameObject g2 = Instantiate(gib2Prefab, gib2Muzzle.transform.position, gib2Muzzle.transform.rotation);

            for (int i = 0; i < FPSMainScript.zombies.Count; i++)
            {
                if (FPSMainScript.zombies[i].uid == uid)
                {
                    FPSMainScript.zombies.RemoveAt(i); break;
                }
            }

            Destroy(this.gameObject);
        }
        else
        {
            if (FPSMainScript.FPSPlayer != null)
            {
                goal = FPSMainScript.FPSPlayer.transform.position;
            }

            if (fa.time >= (offsetTimeset + offsetDelay))
            {
                offsetTimeset = fa.time;
                offsetDelay   = Random.Range(0.5f, 5f);
                offset.x      = Random.Range(-2f, 2f);
                offset.z      = Random.Range(-2f, 2f);
            }

            //Close enough to attack?
            if (Vector3.Distance(goal, transform.position) < 2)
            {
                if (fa.time > (zombieAttackTimeSet + zombieAttackDelay))
                {
                    zombieAttackTimeSet = fa.time;
                    HealthScript h = FPSMainScript.FPSPlayer.GetComponent <HealthScript>();
                    h.health -= Random.Range(zombieMinDam, zombieMaxDam + 1);

                    ScreenShakeCamera.Screenshake(0.2f, 0.1f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                }
            }
            else
            {
                Vector3 oldAngles = transform.localEulerAngles;

                //ok, so move. Can I see the player?
                Ray        ray = new Ray();
                RaycastHit hit;
                LayerMask  mask = 1 << 19;
                float      dist = 0;

                transform.LookAt(FPSMainScript.playerPos);
                ray.origin    = transform.position;
                ray.direction = transform.forward;
                dist          = Vector3.Distance(ray.origin, FPSMainScript.playerPos);

                if (!Physics.Raycast(ray, out hit, dist, mask))
                {
                    //can see the player
                    tempGoal = goal;
                    active   = true;
                }
                else
                {
                    if (active)
                    {
                        //can't see the player. Find the node with the lowest steps, that I can see.
                        int bestYet   = 999;
                        int bestIndex = -1;
                        for (int i = 0; i < PF.nodes.Count; i++)
                        {
                            if (PF.nodes[i].steps < bestYet)                            //If it's worth checking if I can see it
                            {
                                transform.LookAt(PF.nodes[i].go.transform);
                                ray.origin    = transform.position;
                                ray.direction = transform.forward;
                                dist          = Vector3.Distance(ray.origin, PF.nodes[i].go.transform.position);

                                if (!Physics.Raycast(ray, out hit, dist, mask))
                                {
                                    bestYet   = PF.nodes[i].steps;
                                    bestIndex = i;
                                }
                            }
                        }

                        tempGoal = transform.position;
                        if (bestIndex != -1)
                        {
                            tempGoal = PF.nodes[bestIndex].go.transform.position;
                        }
                    }
                }

                if (active)
                {
                    transform.localEulerAngles = oldAngles;
                    transform.LookAt(tempGoal);                    // + offset);
                    transform.Translate(0, 0, speed * Time.deltaTime);
                }
            }
        }
    }
Exemple #8
0
    void HandleBoss()
    {
        float leftX  = Camera.main.gameObject.transform.position.x - 25;
        float rightX = Camera.main.gameObject.transform.position.x + 31;

        switch (state)
        {
        case State.Intro:

            switch (intro)
            {
            case Intro.StartLanding:
                landing_legs.transform.SetY(-8.62f);
                landing_head.transform.SetY(-2f);
                landing_arms.transform.SetY(-4.44f);
                landing_body.transform.SetY(-4.47f);
                landing_legs.transform.AddY(23);
                landing_head.transform.AddY(23);
                landing_arms.transform.AddY(23);
                landing_body.transform.AddY(23);

                iTween.MoveTo(landing_legs, iTween.Hash("delay", 0.3f, "y", -8.62f, "time", 0.3f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_head, iTween.Hash("delay", 0.3f, "y", -2f, "time", 0.27f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_arms, iTween.Hash("delay", 0.3f, "y", -4.44f, "time", 0.33f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_body, iTween.Hash("delay", 0.3f, "y", -4.47f, "time", 0.3f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                intro   = Intro.Impact;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.37f;
                break;

            case Intro.Impact:
                ScreenShakeCamera.Screenshake(2, 0.35f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                GameObject go = Instantiate(blastEffect, blastPoint.transform.position, blastPoint.transform.rotation);
                intro   = Intro.Yell;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.5f;
                break;

            case Intro.Yell:
                //Yell();
                intro   = Intro.AfterYell;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.1f;
                break;

            case Intro.AfterYell:
                intro   = Intro.End;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.1f;
                break;
            }

            break;

        case State.Decide:


            state = State.Charging;


            if (choice == 0)
            {
                choice = 1;
                state  = State.Idle;
            }
            else if (choice == 1)
            {
                state  = State.Charging;
                choice = 0;
            }
            break;

        case State.Waiting:
            if (fa.time > (timeSet + delay))
            {
                timeSet = 0;
                delay   = 0;
                if (intro != Intro.End)
                {                        //If the intro isn't finished, go back to the intro
                    state = State.Intro;
                }
                else
                {
                    state = State.Decide;
                }
            }
            break;

        case State.Idle:
            timeSet = fa.time;
            delay   = 0.8f;
            EnterIdle();
            state = State.Waiting;
            break;

        case State.Charging:

            EnterCharging();

            iTween.MoveTo(Controller_Charging, iTween.Hash("x", leftX, "time", 2f, "easetype", iTween.EaseType.linear));
            iTween.MoveTo(Controller_Charging, iTween.Hash("delay", 2f, "x", rightX, "time", 2f, "easetype", iTween.EaseType.linear));
            iTween.ScaleTo(Controller_ChargingSubController, iTween.Hash("delay", 2f, "x", -1, "time", 0));
            iTween.ScaleTo(Controller_ChargingSubController, iTween.Hash("delay", 4f, "x", 1, "time", 0));

            Controller_Idle.transform.SetX(rightX);

            timeSet = fa.time;
            delay   = 4f;
            state   = State.Waiting;
            break;
        }
    }
Exemple #9
0
    void Update()
    {
        if (fa.paused)
        {
            return;
        }
        if (dimension != Dimensions.currentDimension)
        {
            //make puppet invisible
        }

        lastPos = transform.position;

        spd += spd + (1 * fa.deltaTime);
        if (spd > 55)
        {
            spd = 55;
        }
        transform.Translate(0, 0, spd * fa.deltaTime);

        ray.origin    = lastPos;
        ray.direction = transform.forward;
        float dist = Vector3.Distance(transform.position, lastPos);

        if (Physics.Raycast(ray, out hit, dist, mask))
        {
            float amount = 0;
            if (Vector3.Distance(FPSPlayer.playerPos, hit.point) < 30)
            {
                amount = 0.1f;
            }
            if (Vector3.Distance(FPSPlayer.playerPos, hit.point) < 20)
            {
                amount = 0.3f;
            }
            if (Vector3.Distance(FPSPlayer.playerPos, hit.point) < 10)
            {
                amount = 0.7f;
            }
            ScreenShakeCamera.Screenshake(amount, 0.5f, ScreenShakeCamera.ScreenshakeMethod.Basic);
            //Hit something!

            //Explode!
            GameObject es = Instantiate(exploSound, hit.point, transform.rotation);

            GameObject go;
            go = Instantiate(exploPrefab, hit.point, transform.rotation);

            //hurt everyone in a radius
            float damageRadius = 5;

            if (Vector3.Distance(transform.position, FPSMainScript.playerPos) < damageRadius)
            {
                FPSMainScript.FPSPlayerScript.healthScript.health -= Random.Range(minDam, maxDam + 1);
            }
            for (int i = 0; i < FPSMainScript.zombies.Count; i++)
            {
                if (Vector3.Distance(transform.position, FPSMainScript.zombies[i].transform.position) < damageRadius)
                {
                    FPSMainScript.zombies[i].healthScript.health -= Random.Range(minDam, maxDam + 1);
                }
            }
            for (int i = 0; i < FPSMainScript.demons.Count; i++)
            {
                if (Vector3.Distance(transform.position, FPSMainScript.demons[i].transform.position) < damageRadius)
                {
                    FPSMainScript.demons[i].healthScript.health -= Random.Range(minDam, maxDam + 1);
                }
            }
            for (int i = 0; i < FPSMainScript.anyMonster.Count; i++)
            {
                if (FPSMainScript.anyMonster[i] != null)
                {
                    if (Vector3.Distance(transform.position, FPSMainScript.anyMonster[i].transform.position) < damageRadius)
                    {
                        FPSMainScript.anyMonster[i].health -= Random.Range(minDam, maxDam + 1);
                    }
                }
            }

            //destroy self
            particles.transform.SetParent(null);
            particles.Stop();
            Destroy(this.gameObject);
        }
    }
    void HandleBoss()
    {
        switch (state)
        {
        case State.Intro:

            switch (intro)
            {
            case Intro.StartLanding:
                landing_legs.transform.SetY(-8.62f);
                landing_head.transform.SetY(-2f);
                landing_arms.transform.SetY(-4.44f);
                landing_body.transform.SetY(-4.47f);
                landing_legs.transform.AddY(23);
                landing_head.transform.AddY(23);
                landing_arms.transform.AddY(23);
                landing_body.transform.AddY(23);
                //	Debug.Log("HERE " + Time.timeSinceLevelLoad);
                iTween.MoveTo(landing_legs, iTween.Hash("delay", 0.3f, "y", -8.62f, "time", 0.3f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_head, iTween.Hash("delay", 0.3f, "y", -2f, "time", 0.27f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_arms, iTween.Hash("delay", 0.3f, "y", -4.44f, "time", 0.33f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_body, iTween.Hash("delay", 0.3f, "y", -4.47f, "time", 0.3f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                intro   = Intro.Impact;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.37f;
                break;

            case Intro.Impact:
                ScreenShakeCamera.Screenshake(2, 0.35f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                GameObject go = Instantiate(blastEffect, blastPoint.transform.position, blastPoint.transform.rotation);
                intro   = Intro.Yell;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.5f;
                break;

            case Intro.Yell:
                //Yell();
                intro   = Intro.AfterYell;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.1f;
                break;

            case Intro.AfterYell:
                intro   = Intro.End;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.1f;
                break;
            }

            break;

        case State.Waiting:
            if (intro != Intro.End)
            {
                if (fa.time > (timeSet + delay))
                {
                    timeSet = 0;
                    delay   = 0;
                    state   = State.Intro;
                }
            }
            break;
        }
    }
    void HandleBoss()
    {
        //Debug.Log("State: " + state + ", Intro: " + intro + ", Outro: " + outro + ", choice: " + choice + ", ChoicePhase: " + choiceStage);
        switch (state)
        {
        case State.Intro:

            switch (intro)
            {
            case Intro.StartLanding:
                landing_legs.transform.SetY(-8.62f);
                landing_head.transform.SetY(-2f);
                landing_arms.transform.SetY(-4.44f);
                landing_body.transform.SetY(-4.47f);
                landing_legs.transform.AddY(23);
                landing_head.transform.AddY(23);
                landing_arms.transform.AddY(23);
                landing_body.transform.AddY(23);

                iTween.MoveTo(landing_legs, iTween.Hash("delay", 0.3f, "y", -8.62f, "time", 0.3f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_head, iTween.Hash("delay", 0.3f, "y", -2f, "time", 0.27f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_arms, iTween.Hash("delay", 0.3f, "y", -4.44f, "time", 0.33f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                iTween.MoveTo(landing_body, iTween.Hash("delay", 0.3f, "y", -4.47f, "time", 0.3f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                intro   = Intro.Impact;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.37f;
                break;

            case Intro.Impact:
                ScreenShakeCamera.Screenshake(2, 0.35f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                GameObject go = Instantiate(blastEffect, blastPoint.transform.position, blastPoint.transform.rotation);
                intro   = Intro.Yell;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.5f;
                break;

            case Intro.Yell:
                //Yell();
                intro   = Intro.AfterYell;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.1f;
                break;

            case Intro.AfterYell:
                intro   = Intro.End;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.1f;
                break;
            }

            break;

        case State.Decide:


            if (healthScript.health > 100 && healthScript.health <= 125 && choiceStage != ChoiceStage.Phase2_Fireballs)
            {
                choice = 0; choiceStage = ChoiceStage.Phase2_Fireballs;
            }
            if (healthScript.health > 0 && healthScript.health <= 100 && choiceStage != ChoiceStage.Phase5_CuteGhost)
            {
                choice = 0; choiceStage = ChoiceStage.Phase4_Vanish;
            }
            if (healthScript.health <= 0 && choiceStage != ChoiceStage.Phase99_DerpyGhostDeath)
            {
                choice = 0; choiceStage = ChoiceStage.Phase99_DerpyGhostDeath;
            }


            if (choiceStage == ChoiceStage.Phase1_ChargeAndScythe)
            {
                if (choice == 0)
                {
                    choice = 1;
                    state  = State.Idle;
                }
                else if (choice == 1)
                {
                    state = State.Charging;
                    if (healthScript.health < 180)
                    {
                        choice = 2;
                    }
                    else
                    {
                        choice = 3;
                    }
                }
                else if (choice == 2)
                {
                    state  = State.Attacking;
                    choice = 3;
                }
                else if (choice == 3)
                {
                    choice = 4;
                    state  = State.Stunned;
                }
                else if (choice == 4)
                {
                    choice = 0;
                    state  = State.LongIdle;
                }
            }
            else if (choiceStage == ChoiceStage.Phase2_Fireballs)
            {
                if (choice == 0)
                {
                    choice = 1;
                    state  = State.Idle;
                }
                else if (choice == 1)
                {
                    choice = 2;
                    state  = State.Attacking2;
                }
                else if (choice >= 2)
                {
                    choice = 0;
                    state  = State.Stunned;
                }
            }
            else if (choiceStage == ChoiceStage.Phase4_Vanish)
            {
                choice      = 0;
                state       = State.DieToGhost;
                choiceStage = ChoiceStage.Phase5_CuteGhost;
            }
            else if (choiceStage == ChoiceStage.Phase5_CuteGhost)
            {
                state = State.CuteGhost;
            }
            else if (choiceStage == ChoiceStage.Phase99_DerpyGhostDeath)
            {
                state = State.Outro;
                outro = Outro.StartTweening;
                EnterOutro();
            }



            break;

        case State.Waiting:
            if (fa.time > (timeSet + delay))
            {
                timeSet = 0;
                delay   = 0;
                if (intro != Intro.End)
                {                        //If the intro isn't finished, go back to the intro
                    state = State.Intro;
                }
                else if (outro != Outro.End && outro != Outro.NotStartedYet)
                {
                    state = State.Outro;
                }
                else if (lastState == State.DieToGhost)
                {
                    state = State.DieToGhost2;
                }
                else
                {
                    state = State.Decide;
                }
            }
            break;

        case State.Idle:
            timeSet = fa.time;
            delay   = 0.8f;
            EnterIdle();
            state = State.Waiting;
            break;

        case State.LongIdle:
            timeSet = fa.time;
            delay   = 1f;
            EnterIdle();
            state = State.Waiting;
            break;

        case State.Stunned:
            timeSet = fa.time;
            delay   = 5;
            EnterStunned();
            GameObject g4 = Instantiate(aboutToFlipPrefab, stunnedMuzzlePoint.transform.position, stunnedMuzzlePoint.transform.rotation);

            state = State.Waiting;
            break;

        case State.Attacking:
            timeSet = fa.time;
            delay   = 3;
            EnterAttacking();
            state = State.Waiting;

            GameObject g1 = Instantiate(scythPrefab, muzzlePoint1.transform.position, muzzlePoint1.transform.rotation);
            //GameObject g2 = Instantiate(scythPrefab,muzzlePoint2.transform.position,muzzlePoint2.transform.rotation);
            GameObject   g3 = Instantiate(scythPrefab, muzzlePoint3.transform.position, muzzlePoint3.transform.rotation);
            ScytheScript ss = null;
            ss     = g1.GetComponent <ScytheScript>();
            ss.vel = new Vector3(-6, -6, 0);
            //ss = g2.GetComponent<ScytheScript>();
            //ss.vel = new Vector3(-14,11,0);
            ss     = g3.GetComponent <ScytheScript>();
            ss.vel = new Vector3(-6, 4, 0);

            break;

        case State.Attacking2:
            timeSet = fa.time;
            delay   = 5;
            EnterAttacking2();
            state = State.Waiting;

            break;

        case State.Big:
            timeSet = fa.time;
            delay   = 3;
            EnterBig();
            state = State.Waiting;

            break;

        case State.Charging:

            EnterCharging();
            iTween.MoveTo(Controller_Charging, iTween.Hash("x", -21.5f, "time", 1f, "easetype", iTween.EaseType.linear));
            iTween.MoveTo(Controller_Charging, iTween.Hash("delay", 1f, "x", 10.27f, "time", 1f, "easetype", iTween.EaseType.linear));
            iTween.ScaleTo(Controller_ChargingSubController, iTween.Hash("delay", 1f, "x", -1, "time", 0));
            iTween.ScaleTo(Controller_ChargingSubController, iTween.Hash("delay", 2f, "x", 1, "time", 0));

            timeSet = fa.time;
            delay   = 2f;
            state   = State.Waiting;
            break;

        case State.DieToGhost:
            EnterDieToGhost();
            dieToGhost_AniScript.Play();

            dieToGhost_Ghost.transform.SetX(3.5f);
            dieToGhost_Ghost.transform.SetY(-14.86f);
            iTween.MoveTo(dieToGhost_Ghost, iTween.Hash("delay", 1f, "y", 0.14, "time", 1f, "easetype", iTween.EaseType.easeInOutSine));

            lastState = State.DieToGhost;
            timeSet   = fa.time;
            delay     = 2f;
            state     = State.Waiting;
            break;

        case State.DieToGhost2:
            if (xa.pgMode)
            {
                DieToGhostText.text = "Cray cray, bro bro!";
            }
            else
            {
                DieToGhostText.text = "F**k it!";
            }
            iTween.MoveTo(dieToGhost_Ghost, iTween.Hash("delay", 1f, "y", 18.11, "time", 1f, "easetype", iTween.EaseType.easeInOutSine));

            Instantiate(dieToGhost_Corpse, dieToGhost_CorpseMuzzlePoint.transform.position, dieToGhost_CorpseMuzzlePoint.transform.rotation);

            lastState = State.None;
            timeSet   = fa.time;
            delay     = 3f;
            state     = State.Waiting;
            break;

        case State.CuteGhost:

            EnterCuteGhost();

            if (nonRandomCuteGhostCycle == 0)
            {
                nonRandomCuteGhostCycle       = 1;
                ghostSkull.transform.position = new Vector3(19f, 9.5f, 55);
                iTween.MoveTo(ghostSkull, iTween.Hash("x", -28.9f, "y", -9.1f, "time", 5f, "easetype", iTween.EaseType.linear));
            }
            else if (nonRandomCuteGhostCycle == 1)
            {
                nonRandomCuteGhostCycle       = 2;
                ghostSkull.transform.position = new Vector3(4.1f, 16.2f, 55);
                iTween.MoveTo(ghostSkull, iTween.Hash("x", -3.7f, "y", -13f, "time", 5f, "easetype", iTween.EaseType.linear));
            }
            else if (nonRandomCuteGhostCycle == 2)
            {
                nonRandomCuteGhostCycle       = 3;
                ghostSkull.transform.position = new Vector3(21f, 5f, 55);
                iTween.MoveTo(ghostSkull, iTween.Hash("x", -30f, "y", 5f, "time", 5f, "easetype", iTween.EaseType.linear));
            }
            else if (nonRandomCuteGhostCycle == 3)
            {
                nonRandomCuteGhostCycle       = 0;
                ghostSkull.transform.position = new Vector3(21f, -4.4f, 55);
                iTween.MoveTo(ghostSkull, iTween.Hash("x", -30f, "y", -4.4f, "time", 5f, "easetype", iTween.EaseType.linear));
            }


            timeSet = fa.time;
            delay   = 6f;
            state   = State.Waiting;
            break;

        case State.Outro:

            switch (outro)
            {
            case Outro.StartTweening:
                toSay          = "Nooooooooooooo!\nMy beautiful butt!";
                OutroText.text = "";
                firstYell      = false;
                finalSkull.transform.SetX(31);
                finalSkull.transform.SetY(-9);

                iTween.MoveTo(finalSkull, iTween.Hash("x", -4f, "y", -2f, "time", 2f, "easetype", iTween.EaseType.easeOutSine, "looptype", iTween.LoopType.none));
                outro   = Outro.Yell;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 2.2f;
                break;

            case Outro.Yell:
                if (!firstYell)
                {
                    firstYell = true;
                    Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.MegaSatan_Scream);
                }
                if (toSay.Length > 0)
                {
                    string chop = "" + toSay[0];
                    toSay           = toSay.Remove(0, 1);
                    OutroText.text += chop;

                    outro = Outro.Yell;
                    delay = 0.05f;
                }
                else
                {
                    outro = Outro.AfterYell;
                    delay = 0.5f;
                }

                state   = State.Waiting;
                timeSet = fa.time;
                break;

            case Outro.AfterYell:
                outro   = Outro.DropButt;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 0.1f;
                break;

            case Outro.DropButt:

                goldenButt.transform.SetParent(null, true);
                //goldenButt.transform.SetScaleX(12);
                //goldenButt.transform.SetScaleY(12);
                iTween.MoveTo(goldenButt, iTween.Hash("x", -2f, "y", -8.9f, "time", 1f, "easetype", iTween.EaseType.easeOutBounce));
                iTween.RotateBy(goldenButt, iTween.Hash("z", 1, "time", 1f, "easetype", iTween.EaseType.easeInOutSine));

                Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.MegaSatan_Bounce);

                outro   = Outro.Explode;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 2f;
                break;

            case Outro.Explode:

                Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.MegaSatan_Explo);
                //ScreenShakeCamera.Screenshake(2, 0.45f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                Instantiate(flameDeathExplo, outroMuzzlePoint.transform.position, outroMuzzlePoint.transform.rotation);
                Instantiate(sparksDeathExplo, outroMuzzlePoint.transform.position, outroMuzzlePoint.transform.rotation);
                Instantiate(epicDeathPinwheel, outroMuzzlePoint.transform.position, outroMuzzlePoint.transform.rotation);



                outro   = Outro.Portal;
                state   = State.Waiting;
                timeSet = fa.time;
                delay   = 3f;
                break;

            case Outro.Portal:
                portal.SetActive(true);
                outro   = Outro.End;
                state   = State.Dead;
                timeSet = fa.time;
                delay   = 1f;
                break;
            }

            break;
        }
    }
Exemple #12
0
    public void SwordUpdate()
    {
        if (Controls.GetInputDown(Controls.Type.Jump, novaPlayerScript.playerNumber) && !xa.playerHasJetpack)
        {
            //Debug.Log("PRESSED JUMP WHILE AIRSWORDING");
            storedJump = true;
        }

        switch (swordState)
        {
        case SwordState.Setup:
        {
            hitDeadlyBoxCollider = false;
            swordDir             = Vector3.zero;
            if (xa.playerControlsHeldDir < 0)
            {
                swordDir.x = -1;
            }
            if (xa.playerControlsHeldDir >= 0)
            {
                swordDir.x = 1;
            }
            swordState = SwordState.Charge;

            //play sound effect
            Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.SwordSlice);

            ScreenSlash.ScreenSlashOn(transform.position.y);

            previousTime         = Time.timeScale;
            Time.timeScale       = timeSlowEffect;
            xa.playerAirSwording = true;
            //gotBoost = false;
            novaPlayerScript.Unstick();
        }
        break;

        case SwordState.Charge:
        {
            float dist = swordSpeed * fa.deltaTime;


            //raycast for blocks

            LayerMask  swordMask = 1 << 19 | 1 << 21;                           //Only hits hitboxes on the NovaBlock layer
            Ray        ray       = new Ray();
            RaycastHit hit1      = new RaycastHit();
            RaycastHit hit2      = new RaycastHit();
            RaycastHit hit3      = new RaycastHit();
            ray.direction = swordDir;
            float   tempSpeed            = swordSpeed;
            bool    hitSomething         = false;
            bool    raycastsHitSomething = false;
            float   half = (novaPlayerScript.plHeight * 0.5f);                          // + 0.1f;//ghx
            Vector3 v1   = Vector3.zero;
            Vector3 v2   = Vector3.zero;


            float raycastLayer = xa.GetLayer(xa.layers.RaycastLayer);
            ray.origin = new Vector3(transform.position.x, transform.position.y, raycastLayer);
            v1         = ray.origin; v1.z = 33;
            if (Physics.Raycast(ray, out hit1, dist, swordMask))
            {
                /* v2 = hit1.point; v2.z = 33; Debug.DrawLine(v1, v2, Color.yellow, 5);*/
                raycastsHitSomething = true;
            }


            ray.origin = new Vector3(transform.position.x, transform.position.y + half, raycastLayer);
            v1         = ray.origin; v1.z = 33;
            if (Physics.Raycast(ray, out hit2, dist, swordMask))
            {
                /* v2 = hit2.point; v2.z = 33; Debug.DrawLine(v1, v2, Color.yellow, 5);*/
                raycastsHitSomething = true;
            }



            ray.origin = new Vector3(transform.position.x, transform.position.y - half, raycastLayer);
            v1         = ray.origin; v1.z = 33;
            if (Physics.Raycast(ray, out hit3, dist, swordMask))
            {
                /* v2 = hit3.point; v2.z = 33;Debug.DrawLine(v1, v2, Color.yellow, 5); */
                raycastsHitSomething = true;
            }


            if (raycastsHitSomething)
            {
                float    finalDist     = 9999;
                Vector3  finalPoint    = Vector3.zero;
                Collider finalCollider = null;
                int      hitChoice     = 0;
                float    dist1         = 9999;
                float    dist2         = 9999;
                float    dist3         = 9999;

                if (hit1.collider != null)
                {
                    dist1 = hit1.distance;
                }
                if (hit2.collider != null)
                {
                    dist2 = hit2.distance;
                }
                if (hit3.collider != null)
                {
                    dist3 = hit3.distance;
                }

                hitChoice = 3;
                if (dist1 <= dist2 && dist1 <= dist3)
                {
                    hitChoice = 1;
                }
                if (dist2 <= dist1 && dist2 <= dist3)
                {
                    hitChoice = 2;
                }
                if (dist3 <= dist1 && dist3 <= dist2)
                {
                    hitChoice = 3;
                }
                //Debug.Log("Hit choice: " + hitChoice + ", D1: " + dist1 + ", D2: " + dist2 + ", D3: " + dist3);
                if (hitChoice == 1)
                {
                    finalDist = hit1.distance; finalPoint = hit1.point; finalCollider = hit1.collider;
                }
                if (hitChoice == 2)
                {
                    finalDist = hit2.distance; finalPoint = hit2.point; finalCollider = hit2.collider;
                }
                if (hitChoice == 3)
                {
                    finalDist = hit3.distance; finalPoint = hit3.point; finalCollider = hit3.collider;
                }



                //	Debug.Log("HIT SOMETHING");
                tempSpeed    = finalDist;
                hitSomething = true;
                transform.SetX(finalPoint.x);

                /*
                 * //Debug.Log("AirSwordHitSOmething: " + xa.playerBoxWidth + ", " + xa.playerBoxHeight);
                 * Vector3 a1 = transform.position;
                 * a1.z = 33;
                 * Vector2 a2;
                 *
                 * //draw up
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.y += xa.playerBoxHeight * 0.5f;
                 * //Debug.DrawLine(a1, a2, Color.green, 5);
                 *
                 * //draw down
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.y -= xa.playerBoxHeight * 0.5f;
                 * //Debug.DrawLine(a1, a2, Color.green, 5);
                 *
                 * //draw left
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.x -= xa.playerBoxWidth * 0.5f;
                 * //Debug.DrawLine(a1, a2, Color.green, 5);
                 *
                 * //draw right
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.x += xa.playerBoxWidth * 0.5f;
                 * Debug.DrawLine(a1, a2, Color.green, 5);
                 *
                 *
                 * //draw along the top
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.y += xa.playerBoxHeight * 0.5f;
                 * a2.x -= xa.playerBoxWidth * 0.5f;
                 * Debug.DrawLine(a1, a2, Color.green, 5);
                 *
                 * //draw along the bottom
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.y -= xa.playerBoxHeight * 0.5f;
                 * a2.x -= xa.playerBoxWidth * 0.5f;
                 * Debug.DrawLine(a1, a2, Color.green, 5);
                 *
                 * //draw along the left
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.y += xa.playerBoxHeight * 0.5f;
                 * a2.x += xa.playerBoxWidth * 0.5f;
                 * Debug.DrawLine(a1, a2, Color.green, 5);
                 *
                 * //draw along the right
                 * a2 = new Vector3(a1.x, a1.y, a1.z);
                 * a2.y -= xa.playerBoxHeight * 0.5f;
                 * a2.x += xa.playerBoxWidth * 0.5f;
                 * Debug.DrawLine(a1, a2, Color.green, 5);
                 */
                Info infoScript = null;
                if (hitChoice == 1)
                {
                    infoScript = hit1.collider.GetComponent <Info>();
                }
                if (hitChoice == 2)
                {
                    infoScript = hit2.collider.GetComponent <Info>();
                }
                if (hitChoice == 3)
                {
                    infoScript = hit3.collider.GetComponent <Info>();
                }
                if (infoScript != null)
                {
                    if (infoScript.killPlayer)
                    {
                        hitDeadlyBoxCollider = true;
                    }
                }

                HittableByAirsword hittableScript = finalCollider.gameObject.GetComponent <HittableByAirsword>();
                if (hittableScript != null)
                {
                    hittableScript.HitByPlayer();

                    /*if (hittableScript.giveAirswordBoost)
                     * {
                     *      gotBoost = true;
                     * }*/
                }
            }

            if (hitSomething)
            {
                swordState = SwordState.WrapUp;
            }
            else
            {
                Vector3 swordVel = new Vector3();
                swordVel.x = (swordDir.x * tempSpeed) * fa.deltaTime;
                swordVel.y = (swordDir.y * tempSpeed) * fa.deltaTime;


                int split = 15;
                for (int m = split; m > 0; m--)
                {
                    CheckForItems(dist * 1f, transform.position);
                    CheckHurtZones();
                    transform.Translate(swordVel / split);
                }

                //transform.Translate(swordVel);
            }



            if (!NovaPlayerScript.checkPlayerDeathBox(transform.position) && !novaPlayerScript.ThreeDee)
            {
                novaPlayerScript.hpScript.health = 0;
                swordState = SwordState.WrapUp;
            }

            if (novaPlayerScript.hpScript.health <= 0)
            {
                swordState = SwordState.WrapUp;
            }
        }
        break;

        case SwordState.WrapUp:
        {
            if (novaPlayerScript.altTrailPS_Normal != null)
            {
                novaPlayerScript.altTrailPS_Normal.Play();
                novaPlayerScript.altTrailPS_Airsword.Stop();
            }
            ScreenSlash.ScreenSlashOff();
            Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.RockImpact);
            ScreenShakeCamera.Screenshake(1, 0.25f, ScreenShakeCamera.ScreenshakeMethod.Basic);
            xa.playerAirSwording = false;
            Time.timeScale       = previousTime;                      //1f;
            //Time.timeScale = 0.7f;//previousTime;//1f;
            swordState                         = SwordState.Setup;
            novaPlayerScript.state             = NovaPlayerScript.State.NovaPlayer;
            novaPlayerScript.DidAirSwordImpact = true;
            novaPlayerScript.vel.y             = 0;

            if (hitDeadlyBoxCollider)
            {
                novaPlayerScript.hpScript.health = 0;
            }

            if (novaPlayerScript.hpScript.health <= 0)
            {
                if (novaPlayerScript.hpScript.setPosWhenKilled)
                {
                    transform.SetX(novaPlayerScript.hpScript.posWhenKilled.x);
                    transform.SetY(novaPlayerScript.hpScript.posWhenKilled.y);
                }
            }

            /*if (gotBoost)
             * {
             *      novaPlayerScript.GotAirswordBoost();
             * }*/

            if (storedJump)
            {
                storedJump = false;
                novaPlayerScript.ExternalPossibleJump();
            }
        }
        break;
        }
    }
Exemple #13
0
    void Update()
    {
        if (healthScript != null && healthScript.health <= 0)
        {
            return;
        }

        if (unicorn)
        {
            if (CheckRaycast() || charging)
            {
                charging  = true;
                moveSpeed = unicornChargeSpd;
            }
            else
            {
                moveSpeed = unicornWalkSpd;
            }
        }

        //If the player is far enough away from me, destroy me (as I'm probably a spawned monster)
        if (destroyWhenFarAwayFromPlayer)
        {
            if (xa.player != null)
            {
                if (Vector2.Distance(xa.player.transform.position, transform.position) > 50)
                {
                    Destroy(this.gameObject);
                }
            }
        }

        //Check for ground
        ray.origin    = new Vector3(checkForGroundPoint.transform.position.x, checkForGroundPoint.transform.position.y, xa.GetLayer(xa.layers.RaycastLayer));
        ray.direction = new Vector3(0, -1, 0);
        mask          = 1 << 19;
        //Debug.DrawLine(new Vector3(ray.origin.x, ray.origin.y, 15), ray.GetPoint(checkForGroundDist), Color.yellow);
        if (Physics.Raycast(ray, out hit, checkForGroundDist, mask))
        {
            transform.SetY(hit.point.y + checkForGroundDist);
            falling = false;
        }
        else
        {
            falling = true;
        }

        //Check for walls
        if (checkForWalls)
        {
            ray.origin    = new Vector3(checkForWallsPoint.transform.position.x, checkForWallsPoint.transform.position.y, xa.GetLayer(xa.layers.RaycastLayer));
            ray.direction = new Vector3(-transform.localScale.x, 0, 0);
            mask          = 1 << 19 | 1 << 25;
            //Debug.DrawLine(new Vector3(ray.origin.x, ray.origin.y, 15), ray.GetPoint(checkForWallsDist), Color.yellow);
            if (Physics.Raycast(ray, out hit, checkForWallsDist, mask))
            {
                transform.SetScaleX(-transform.localScale.x);

                if (charging)
                {
                    charging = false;
                    Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.RockImpact);
                    ScreenShakeCamera.Screenshake(0.2f, 0.15f, ScreenShakeCamera.ScreenshakeMethod.Basic);


                    Vector3 pos = hit.point;
                    pos.y += 0.19f;
                    pos.z  = xa.GetLayer(xa.layers.Explo1);
                    Vector3 dir = new Vector3(0, 0, 0);
                    if (transform.localScale.x == 1)
                    {
                        dir = new Vector3(0, -90, 90);
                    }
                    if (transform.localScale.x == -1)
                    {
                        dir = new Vector3(-180, -90, 90);
                    }

                    GameObject tempGo = Instantiate(impactDust, pos, Quaternion.Euler(dir));
                    tempGo.transform.SetParent(xa.createdObjects.transform);
                }
            }
        }



        //is the ground under me?
        if (falling)
        {
            vel.y -= gravity * Time.deltaTime * fa.pausedFloat;
            if (vel.y < -8)
            {
                vel.y = -8;
            }

            //vel.x += 0.2f * Time.deltaTime;
            //if(vel.x > 0) {vel.x = 0; }

            vel.x = 0;
        }
        else
        {
            vel.x = -moveSpeed * Time.deltaTime * fa.pausedFloat * transform.localScale.x;
            vel.y = 0;
        }

        transform.Translate(vel);
    }
    void Update()
    {
        if (fa.paused)
        {
            return;
        }
        //changing hurt state

        if (!hurt1 && healthScript.health <= FPSBalanceScript.MegaSatanHurtHP1)
        {
            hurt1 = true;
            Mesh_IdleHead.material = IdleHeadHurtMat1;
            Mesh_FPSHead.material  = FPSHeadHurtMat1;
        }
        if (!hurt2 && healthScript.health <= FPSBalanceScript.MegaSatanHurtHP2)
        {
            hurt2 = true;
            Mesh_IdleHead.material = IdleHeadHurtMat2;
            Mesh_FPSHead.material  = FPSHeadHurtMat2;
        }
        //getting hit
        if (oldHealth != healthScript.health)
        {
            oldHealth = healthScript.health;
            //got hit

            iTween.PunchRotation(IdleHead, iTween.Hash("z", Random.Range(-45, 45), "time", Random.Range(0.3f, 0.5f), "easetype", iTween.EaseType.linear));
            iTween.PunchRotation(IdleBody, iTween.Hash("z", Random.Range(-45, 45), "time", Random.Range(0.3f, 0.5f), "easetype", iTween.EaseType.linear));
            iTween.PunchRotation(ChargingHead, iTween.Hash("z", Random.Range(-45, 45), "time", Random.Range(0.3f, 0.5f), "easetype", iTween.EaseType.linear));
            iTween.PunchRotation(ChargingBody, iTween.Hash("z", Random.Range(-45, 45), "time", Random.Range(0.3f, 0.5f), "easetype", iTween.EaseType.linear));
        }

        float delay = 1;

        if (state == State.Charging)
        {
            delay = stateChargeTime;
        }
        if (state == State.Firing)
        {
            delay = stateFiringTime;
        }
        if (fa.time >= (delay + stateTimeSet))
        {
            stateTimeSet = fa.time;
            if (state == State.Charging)
            {
                state = State.Firing;
                ChargingController.SetActive(false);
                IdleController.SetActive(true);
                Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.FPSMS_Scream1);
            }
            else
            {
                state = State.Charging;
                ChargingController.SetActive(true);
                IdleController.SetActive(false);
                Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.FPSMS_Scream2);
            }
        }


        if (state == State.Firing)
        {
            if (fa.time > (firingSpeed_TimeSet + firingSpeed_Delay))
            {
                Vector3 target = Vector3.zero;

                if (FPSMainScript.FPSPlayer != null)
                {
                    target = FPSMainScript.FPSPlayer.transform.position;
                }
                muzzlePoint.transform.LookAt(target);                // + offset);
                firingSpeed_TimeSet = fa.time;
                GameObject go = Instantiate(zombiePrefab, muzzlePoint.transform.position, muzzlePoint.transform.rotation);
                go = Instantiate(bulletPrefab, muzzlePoint.transform.position, muzzlePoint.transform.rotation);
            }
        }


        if (healthScript.health <= 0)
        {
            GameObject g1 = Instantiate(HeadGib, HeadGibMuzzle.transform.position, HeadGibMuzzle.transform.rotation);
            Instantiate(GenericGib1, GenericGibMuzzle1.transform.position, GenericGibMuzzle1.transform.rotation);
            Instantiate(GenericGib1, GenericGibMuzzle2.transform.position, GenericGibMuzzle2.transform.rotation);
            Instantiate(GenericGib1, GenericGibMuzzle3.transform.position, GenericGibMuzzle3.transform.rotation);
            Instantiate(GenericGib2, GenericGibMuzzle4.transform.position, GenericGibMuzzle4.transform.rotation);
            Instantiate(GenericGib2, GenericGibMuzzle5.transform.position, GenericGibMuzzle5.transform.rotation);
            Instantiate(GenericGib2, GenericGibMuzzle6.transform.position, GenericGibMuzzle6.transform.rotation);

            portal.transform.SetX(transform.position.x);
            portal.transform.SetZ(transform.position.z);
            Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.FPSMS_Death);
            GameObject go = Instantiate(corpse, transform.position, corpse.transform.rotation);

            for (int i = 0; i < FPSMainScript.anyMonster.Count; i++)
            {
                if (FPSMainScript.anyMonster[i].uid == uid)
                {
                    FPSMainScript.anyMonster.RemoveAt(i); break;
                }
            }

            Destroy(this.gameObject);
        }
        else
        {
            if (FPSMainScript.FPSPlayer != null)
            {
                goal = FPSMainScript.FPSPlayer.transform.position;
            }

            //Close enough to melee attack?
            if (Vector3.Distance(goal, transform.position) < 2)
            {
                if (fa.time > (attackTimeSet + attackDelay))
                {
                    attackTimeSet = fa.time;
                    HealthScript h = FPSMainScript.FPSPlayer.GetComponent <HealthScript>();
                    h.health -= Random.Range(minDam, maxDam + 1);

                    ScreenShakeCamera.Screenshake(0.1f, 0.1f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                }
            }
            else
            {
                if (state == State.Charging)                //if moving
                {
                    Vector3 oldAngles = transform.localEulerAngles;

                    //ok, so move. Can I see the player?
                    Ray        ray = new Ray();
                    RaycastHit hit;
                    LayerMask  mask = 1 << 19;
                    float      dist = 0;

                    transform.LookAt(FPSMainScript.playerPos);
                    ray.origin    = transform.position;
                    ray.direction = transform.forward;
                    dist          = Vector3.Distance(ray.origin, FPSMainScript.playerPos);

                    if (!Physics.Raycast(ray, out hit, dist, mask))
                    {
                        //can see the player
                        tempGoal = goal;
                        if (active == false)
                        {
                            Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.FPSMS_Intro);
                        }
                        active = true;
                    }
                    else
                    {
                        if (active)
                        {
                            //can't see the player. Find the node with the lowest steps, that I can see.
                            int bestYet   = 999;
                            int bestIndex = -1;
                            for (int i = 0; i < PF.nodes.Count; i++)
                            {
                                if (PF.nodes[i].steps < bestYet)                                //If it's worth checking if I can see it
                                {
                                    transform.LookAt(PF.nodes[i].go.transform);
                                    ray.origin    = transform.position;
                                    ray.direction = transform.forward;
                                    dist          = Vector3.Distance(ray.origin, PF.nodes[i].go.transform.position);

                                    if (!Physics.Raycast(ray, out hit, dist, mask))
                                    {
                                        bestYet   = PF.nodes[i].steps;
                                        bestIndex = i;
                                    }
                                }
                            }

                            tempGoal = transform.position;
                            if (bestIndex != -1)
                            {
                                tempGoal = PF.nodes[bestIndex].go.transform.position;
                            }
                        }
                    }

                    if (active)
                    {
                        if (tempGoal.x > 36)
                        {
                            tempGoal.x = 36;
                        }
                        if (tempGoal.x < 12)
                        {
                            tempGoal.x = 12;
                        }
                        if (tempGoal.z > -72)
                        {
                            tempGoal.z = -72;
                        }
                        if (tempGoal.z < -96)
                        {
                            tempGoal.z = -96;
                        }
                        ScreenShakeCamera.Screenshake(0.01f, 0.1f, ScreenShakeCamera.ScreenshakeMethod.Basic);
                        transform.localEulerAngles = oldAngles;
                        transform.LookAt(tempGoal);                        // + offset);
                        transform.Translate(0, 0, speed * Time.deltaTime);
                        transform.localEulerAngles = oldAngles;
                    }
                }
            }
        }
    }
 void Start()
 {
     ScreenShakeCamera.Screenshake(1, 0.2f, ScreenShakeCamera.ScreenshakeMethod.Basic);
     Fresh_SoundEffects.PlaySound(Fresh_SoundEffects.Type.RockImpact);
 }