コード例 #1
0
    // Start is called before the first frame update
    private void Start()
    {
        // Reference to the song collection script to play the correct audio
        songCollection = GameObject.FindGameObjectWithTag("Audio Player").GetComponent <SongCollection>();

        //set vars and state vars
        idleState       = gameObject.AddComponent <IdleState>();
        chasingState    = gameObject.AddComponent <ChasingState>();
        explodingState  = gameObject.AddComponent <ExplodingState>();
        currentState    = idleState;
        inRange         = false;
        explodingSprite = this.gameObject.transform.GetChild(0).GetComponent <SpriteRenderer>().sprite;
        normalSprite    = this.gameObject.GetComponent <SpriteRenderer>().sprite;

        //get player
        switch (Stats.ActiveRunner)
        {
        case 1:
            player = GameObject.Find("PlayerComp1").transform;
            break;

        case 2:
            player = GameObject.Find("PlayerComp2").transform;
            break;

        case 3:
            player = GameObject.Find("PlayerComp3").transform;
            break;

        case 4:
            player = GameObject.Find("PlayerComp4").transform;
            break;

        default:
            player = GameObject.Find("PlayerComp1").transform;
            break;
        }

        currentState.StopChasing();
    }