コード例 #1
0
 // Start is called before the first frame update
 void Start()
 {
     state       = scp049State.idle;
     currAnim    = scp049State.idle;
     mainCamera  = Camera.main;
     agent       = GetComponent <NavMeshAgent>();
     voiceSource = GetComponent <AudioSource>();
 }
コード例 #2
0
 public void evWalkTo(Vector3 to)
 {
     isEvent    = true;
     currTarget = to;
     state      = scp049State.patrol;
     agent.SetDestination(currTarget);
     Debug.Log("Walking Event");
 }
コード例 #3
0
 public override void Spawn(bool beActive, Vector3 warppoint)
 {
     base.Spawn(beActive, warppoint);
     data.isActive = beActive;
     animator.Rebind();
     agent.isStopped = false;
     state           = scp049State.idle;
     currAnim        = state;
     agent.Warp(warppoint);
 }
コード例 #4
0
    public override void StopEvent()
    {
        Debug.Log("Finishing event");
        base.StopEvent();
        Timer   = 0;
        isEvent = false;

        data.isActive = true;
        animator.Rebind();
        state    = scp049State.idle;
        currAnim = state;
    }
コード例 #5
0
 public override void Event_Spawn(bool instant, Vector3 warppoint)
 {
     agent.speed     = chaseSpeed;
     data.isActive   = true;
     isEvent         = true;
     agent.isStopped = false;
     base.Event_Spawn(instant, warppoint);
     agent.Warp(warppoint);
     animator.Rebind();
     state    = scp049State.idle;
     currAnim = state;
     agent.Warp(warppoint);
 }
コード例 #6
0
    void NPCEvent()
    {
        if (Time.frameCount % framerate == 0)
        {
            distanceFromPlayer = Vector3.Distance(transform.position, GameController.instance.playercache.transform.position);
            //Debug.Log("Distance " + distanceFromPlayer);
            seePlayer = CanSee();
        }

        switch (state)
        {
        case scp049State.idle:
        {
            agent.ResetPath();
            break;
        }

        case scp049State.patrol:
        {
            agent.speed = chaseSpeed;

            if (Time.frameCount % framerate == 0)
            {
                agent.SetDestination(currTarget);
                if (agent.hasPath && agent.remainingDistance < 0.5f)
                {
                    Debug.Log("Honey im home");
                    state = scp049State.idle;
                }
            }
            RaycastHit hit;
            if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out hit, 4f, doors))
            {
                hit.transform.gameObject.GetComponent <Object_Door>().ForceOpen(5);
            }
            break;
        }
        }

        if (isRota)
        {
            ACT_Rotation();
        }
    }
コード例 #7
0
 /// <summary>
 /// Change 096 fake state
 /// </summary>
 /// <param name="newState">state (0 = idle, sitting, patrol, panic, run, attack)</param>
 public void evChangeState(int newState)
 {
     isEvent = true;
     state   = (scp049State)newState;
 }
コード例 #8
0
    void NPCUpdate()
    {
        seePlayer = false;
        if (debugIsTargeting && Time.frameCount % framerate == 0)
        {
            distanceFromPlayer = Vector3.Distance(transform.position, GameController.instance.playercache.transform.position);
            seePlayer          = CanSee();
            if (seePlayer)
            {
                if (!isPlayingChase)
                {
                    GameController.instance.npcController.npcLevel(npc.scp049);
                    GameController.instance.ChangeMusic(chaseSong);
                    isPlayingChase = true;
                }
                currTarget    = GameController.instance.playercache.transform.position;
                teleportTimer = 0;
            }

            if (state != scp049State.chase && state != scp049State.kill && seePlayer)
            {
                data.npcvalue[valIsPanic] = 1;
                state    = scp049State.chase;
                audTimer = 0;
            }

            if (distanceFromPlayer > 15f && isPlayingChase)
            {
                GameController.instance.DefMusic();
                isPlayingChase = false;
            }
        }



        teleportTimer += Time.deltaTime;

        if (Time.frameCount % framerate == 0 && !foundSound)
        {
            CheckSounds();
        }

        if (Time.frameCount % framerate2 == 0 && teleportTimer > levels[data.npcvalue[0]].timeBeforeTele && distanceFromPlayer > levels[data.npcvalue[0]].distanceTele)
        {
            Vector3 teleportTo;
            teleportTo = GameController.instance.GetPatrol(GameController.instance.player.transform.position, levels[data.npcvalue[0]].maxTele, levels[data.npcvalue[0]].minTele);
            Spawn(true, teleportTo);
            teleportTimer   = 0;
            agent.isStopped = false;
        }
        ///DEBUG DATA
        //Debug.DrawRay(transform.position + Vector3.up, (GameController.instance.playercache.transform.position - transform.position));
        //Debug.Log("Dot de vision " + Vector3.Dot((GameController.instance.playercache.transform.position - transform.position).normalized, transform.forward));


        //Current State
        switch (state)
        {
        case scp049State.idle:
        {
            onPath = false;
            agent.ResetPath();
            if (foundSound)
            {
                if (currSoundLevel < 2)
                {
                    audTimer   = 0;
                    foundSound = false;
                    state      = scp049State.hearing;
                    Timer      = Random.Range(5, 10);
                }
                else
                {
                    audTimer = 0;
                    state    = scp049State.soundChase;
                    onPath   = false;
                }
                foundSound = false;
            }
            break;
        }

        case scp049State.trailIdle:
        case scp049State.hearing:
        {
            agent.ResetPath();
            if (foundSound)
            {
                if (currSoundLevel > 0)
                {
                    audTimer = 0;
                    state    = scp049State.soundChase;
                    onPath   = false;
                }
            }
            break;
        }

        case scp049State.trail:
        {
            agent.speed = normalSpeed;

            if (foundSound)
            {
                if (currSoundLevel < 1)
                {
                    audTimer   = 0;
                    state      = scp049State.hearing;
                    Timer      = Random.Range(3, 10);
                    foundSound = false;
                }
                else
                {
                    audTimer = 0;
                    state    = scp049State.soundChase;
                    onPath   = false;
                }
            }

            RaycastHit hit;
            if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out hit, 0.5f, doors))
            {
                if (!hit.transform.gameObject.GetComponent <Object_Door>().GetState())
                {
                    agent.isStopped = true;
                    agent.velocity  = Vector3.zero;
                    Timer          += Time.deltaTime;
                }
                else
                {
                    agent.isStopped = false;
                    if (!agent.hasPath || agent.pathStatus == NavMeshPathStatus.PathInvalid)
                    {
                        agent.SetDestination(getRandomPoint());
                    }
                }
                hit.transform.gameObject.GetComponent <Object_Door>().ForceOpen(5);
            }
            else
            {
                agent.isStopped = false;
                if (!agent.hasPath || agent.pathStatus == NavMeshPathStatus.PathInvalid)
                {
                    agent.SetDestination(getRandomPoint());
                }
            }

            break;
        }

        case scp049State.patrol:
        {
            agent.speed = normalSpeed;



            if (foundSound)
            {
                if (currSoundLevel < 2)
                {
                    audTimer   = 0;
                    state      = scp049State.hearing;
                    Timer      = Random.Range(5, 10);
                    foundSound = false;
                }
                else
                {
                    audTimer = 0;
                    state    = scp049State.soundChase;
                }
            }

            if (agent.hasPath && agent.remainingDistance < (pathIsMap ? 5 : 0.5f))
            {
                state   = scp049State.idle;
                onPath  = false;
                hasPath = false;
                Timer   = Random.Range(5, 10);
            }

            RaycastHit hit;
            if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out hit, 0.5f, doors))
            {
                if (!hit.transform.gameObject.GetComponent <Object_Door>().GetState())
                {
                    agent.isStopped = true;
                    agent.velocity  = Vector3.zero;
                    Timer          += Time.deltaTime;
                }
                else
                {
                    agent.isStopped = false;
                    if (!onPath)
                    {
                        agent.SetDestination(getPatrol());
                        onPath = true;
                    }
                }
                hit.transform.gameObject.GetComponent <Object_Door>().ForceOpen(5);
            }
            else
            {
                agent.isStopped = false;
                if (!onPath)
                {
                    agent.SetDestination(getPatrol());
                    onPath = true;
                }
            }

            break;
        }

        case scp049State.soundChase:
        {
            agent.speed = normalSpeed;



            if (agent.hasPath && agent.remainingDistance < 0.5f)
            {
                if (trailTimer > 0)
                {
                    state = scp049State.trail;
                }
                else
                {
                    state = scp049State.idle;
                }
                onPath         = false;
                currSoundLevel = 0;
                Timer          = Random.Range(5, 10);
            }

            RaycastHit hit;
            if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out hit, 0.5f, doors))
            {
                if (!hit.transform.gameObject.GetComponent <Object_Door>().GetState())
                {
                    agent.isStopped = true;
                    agent.velocity  = Vector3.zero;
                    Timer          += Time.deltaTime;
                }
                else
                {
                    agent.isStopped = false;
                    if (!onPath)
                    {
                        agent.SetDestination(currTarget);
                        onPath = true;
                    }
                }
                hit.transform.gameObject.GetComponent <Object_Door>().ForceOpen(5);
            }
            else
            {
                agent.isStopped = false;
                if (!onPath)
                {
                    agent.SetDestination(currTarget);
                    onPath = true;
                }
            }
            break;
        }

        case scp049State.chase:
        {
            foundSound     = false;
            currSoundLevel = 0;
            agent.speed    = chaseSpeed;


            if (agent.hasPath && agent.remainingDistance < 0.5f && distanceFromPlayer > 6f)
            {
                state      = scp049State.trail;
                Timer      = Random.Range(5, 10);
                trailTimer = Random.Range(20, 30);
            }

            animator.SetBool("reach", distanceFromPlayer < 5 && state != scp049State.kill);


            RaycastHit hit;
            if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out hit, 0.5f, doors))
            {
                if (!hit.transform.gameObject.GetComponent <Object_Door>().GetState())
                {
                    agent.isStopped = true;
                    agent.velocity  = Vector3.zero;
                    Timer          += Time.deltaTime;
                }
                else
                {
                    agent.isStopped = false;
                    if (Time.frameCount % framerate == 0)
                    {
                        if (seePlayer || distanceFromPlayer < 10f)
                        {
                            agent.SetDestination(GameController.instance.playercache.transform.position);
                        }
                    }
                }
                hit.transform.gameObject.GetComponent <Object_Door>().ForceOpen(5);
            }
            else
            {
                agent.isStopped = false;
                if (Time.frameCount % framerate == 0)
                {
                    if (seePlayer || distanceFromPlayer < 10f)
                    {
                        agent.SetDestination(GameController.instance.playercache.transform.position);
                    }
                }
            }

            if (Physics.OverlapSphere(transform.position + transform.forward, 0.5f, playerMask).Length > 0 && !GameController.instance.playercache.godmode)
            {
                agent.isStopped = true;
                agent.velocity  = Vector3.zero;
                GameController.instance.deathmsg = Localization.GetString("deathStrings", "death_049");
                GameController.instance.playercache.Death(0);
                Debug.Log("Kill");
                state = scp049State.kill;
                PlayVoice(3);
            }

            break;
        }
        }

        Timer      -= Time.deltaTime;
        trailTimer -= Time.deltaTime;
        audTimer   -= Time.deltaTime;

        if (trailTimer < 0 && (state == scp049State.trailIdle || state == scp049State.trail))
        {
            state = scp049State.idle;
            Timer = Random.Range(5, 10);
        }

        //Next State
        if (Timer < 0)
        {
            switch (state)
            {
            case scp049State.trailIdle:
            {
                state = scp049State.trail;
                Timer = Random.Range(3, 10);
                getRandomPoint();

                break;
            }

            case scp049State.trail:
            {
                state = scp049State.trailIdle;
                Timer = Random.Range(3, 10);
                break;
            }

            case scp049State.idle:
            {
                state = scp049State.patrol;
                Timer = Random.Range(10, 15);
                //getRandomPoint();

                break;
            }

            case scp049State.hearing:
            case scp049State.patrol:
            {
                if (trailTimer > 0)
                {
                    state = scp049State.trail;
                }
                else
                {
                    state = scp049State.idle;
                }
                Timer = Random.Range(5, 10);
                break;
            }
            }
        }

        //Audio state
        if (audTimer < 0)
        {
            switch (state)
            {
            case scp049State.hearing:
            case scp049State.trail:
            case scp049State.trailIdle:
            {
                PlayVoice(1);
                audTimer = Random.Range(8, 15);

                break;
            }

            case scp049State.soundChase:
            case scp049State.chase:
            {
                PlayVoice(2);
                audTimer = Random.Range(8, 13);
                break;
            }
            }
        }
    }