예제 #1
0
    // Use this for initialization
    void Start()
    {
        // find child triggers
        foreach (Transform childTransform in transform)
        {
            if (childTransform.gameObject.CompareTag(GlobalNames.TAG.ShoutingTrigger))
            {
                shoutTrigger = childTransform.gameObject.GetComponent<BoxCollider>();
            }
            else if (childTransform.gameObject.CompareTag(GlobalNames.TAG.WhistlingTrigger))
            {
                whistlingTrigger = childTransform.gameObject;
            }
            else if (childTransform.gameObject.CompareTag(GlobalNames.TAG.ShushTrigger))
            {
                shushTrigger = childTransform.gameObject;
            }
        }

        if (shoutTrigger != null)
        {
            shoutTrigger.gameObject.active = false;
        }
        else
        {
            Debug.LogWarning("Shout trigger on player wasn't found");
        }

        // whistling trigger
        if (whistlingTrigger != null)
        {
            whistlingTrigger.gameObject.active = true;
        }
        else
        {
            Debug.LogWarning("Whistling trigger on player wasn't found");
        }

        // shush trigger
        if (shushTrigger != null)
        {
            shushTrigger.gameObject.active = false;
        }
        else
        {
            Debug.LogWarning("Shush trigger on player wasn't found");
        }

        whistlingSpawn = transform.GetComponentInChildren<WhistlingSpawner>();
        if(whistlingSpawn == null)
            Debug.LogWarning("Whistling spawn wasn't found");

        ConfusingSpawn = transform.GetComponentInChildren<ConfusingSpawner>();
        if (ConfusingSpawn == null)
            Debug.LogWarning("Confusing spawn wasn't found");

        // float particle system
        Transform current;
        for (int i = 0; i < transform.GetChildCount(); i++)
        {
            current = transform.GetChild(i);
            if (current.gameObject.tag == GlobalNames.TAG.FloatParticleSystem)
            {
                FloatParticleSystem = current.gameObject.GetComponent<ParticleSystem>();
                FloatParticleSystem.emissionRate = 0;
                continue;
            }
            else if (current.gameObject.tag == GlobalNames.TAG.ShoutParticleSystem)
            {
                ShoutParticleSystem = current.gameObject.GetComponent<ParticleSystem>();
                shoutEmissionRate = ShoutParticleSystem.emissionRate;
                continue;
            }
        }

        // get renderer
        meshRenderer = transform.GetComponentInChildren<MeshRenderer>();

        // initialize states
        StandState = ScriptableObject.CreateInstance<PStandState>();
        WalkState = ScriptableObject.CreateInstance<PWalkState>();

        JumpState = ScriptableObject.CreateInstance<PJumpState>();
        FallState = ScriptableObject.CreateInstance<PFallState>();
        FloatState = ScriptableObject.CreateInstance<PFloatState>();

        // create the finite state machine
        FSM = new FiniteStateMachine<Player>();
        // configure it so that the player first falls and does not move r/l
        FSM.Configure(this, FallState, null);

        GameObject temp = GameObject.FindGameObjectWithTag(GlobalNames.TAG.StartPoint);
        if (temp != null)
        {
            startTransform = temp.transform;
        }
        else
        {
            Debug.LogWarning("The scene does not have an object tagged with \"StartPoint\"");
        }

        // set tag
        tag = GlobalNames.TAG.Player;

        Reset ();
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        // find child triggers
        foreach (Transform childTransform in transform)
        {
            if (childTransform.gameObject.CompareTag(GlobalNames.TAG.ShoutingTrigger))
            {
                shoutTrigger = childTransform.gameObject.GetComponent <BoxCollider>();
            }
            else if (childTransform.gameObject.CompareTag(GlobalNames.TAG.WhistlingTrigger))
            {
                whistlingTrigger = childTransform.gameObject;
            }
            else if (childTransform.gameObject.CompareTag(GlobalNames.TAG.ShushTrigger))
            {
                shushTrigger = childTransform.gameObject;
            }
        }

        if (shoutTrigger != null)
        {
            shoutTrigger.gameObject.active = false;
        }
        else
        {
            Debug.LogWarning("Shout trigger on player wasn't found");
        }

        // whistling trigger
        if (whistlingTrigger != null)
        {
            whistlingTrigger.gameObject.active = true;
        }
        else
        {
            Debug.LogWarning("Whistling trigger on player wasn't found");
        }

        // shush trigger
        if (shushTrigger != null)
        {
            shushTrigger.gameObject.active = false;
        }
        else
        {
            Debug.LogWarning("Shush trigger on player wasn't found");
        }

        whistlingSpawn = transform.GetComponentInChildren <WhistlingSpawner>();
        if (whistlingSpawn == null)
        {
            Debug.LogWarning("Whistling spawn wasn't found");
        }

        ConfusingSpawn = transform.GetComponentInChildren <ConfusingSpawner>();
        if (ConfusingSpawn == null)
        {
            Debug.LogWarning("Confusing spawn wasn't found");
        }

        // float particle system
        Transform current;

        for (int i = 0; i < transform.GetChildCount(); i++)
        {
            current = transform.GetChild(i);
            if (current.gameObject.tag == GlobalNames.TAG.FloatParticleSystem)
            {
                FloatParticleSystem = current.gameObject.GetComponent <ParticleSystem>();
                FloatParticleSystem.emissionRate = 0;
                continue;
            }
            else if (current.gameObject.tag == GlobalNames.TAG.ShoutParticleSystem)
            {
                ShoutParticleSystem = current.gameObject.GetComponent <ParticleSystem>();
                shoutEmissionRate   = ShoutParticleSystem.emissionRate;
                continue;
            }
        }

        // get renderer
        meshRenderer = transform.GetComponentInChildren <MeshRenderer>();

        // initialize states
        StandState = ScriptableObject.CreateInstance <PStandState>();
        WalkState  = ScriptableObject.CreateInstance <PWalkState>();

        JumpState  = ScriptableObject.CreateInstance <PJumpState>();
        FallState  = ScriptableObject.CreateInstance <PFallState>();
        FloatState = ScriptableObject.CreateInstance <PFloatState>();

        // create the finite state machine
        FSM = new FiniteStateMachine <Player>();
        // configure it so that the player first falls and does not move r/l
        FSM.Configure(this, FallState, null);

        GameObject temp = GameObject.FindGameObjectWithTag(GlobalNames.TAG.StartPoint);

        if (temp != null)
        {
            startTransform = temp.transform;
        }
        else
        {
            Debug.LogWarning("The scene does not have an object tagged with \"StartPoint\"");
        }

        // set tag
        tag = GlobalNames.TAG.Player;

        Reset();
    }