예제 #1
0
 // Use this for initialization
 void Start()
 {
     spirit    = GetComponent <SpiritController>();
     soulLight = GetComponentInChildren <Light>();
     timer     = lightDurability;
 }
예제 #2
0
        void Start()
        {
            GUI                    = GameObject.FindGameObjectWithTag("GameUI");
            interaction            = GUI.GetComponent <Interaction>();
            inventory              = GUI.GetComponent <Inventory>();
            interactable           = false;
            inventoryActive        = false;
            GeneralData.gamePaused = false;

            // get the last digit of the player name (1 / 2)
            playerNum  = this.transform.name[this.transform.name.Length - 1];
            playerNum -= 48;

            // Set Input system
            if (playerNum == 1)
            {
                input = GeneralData.inputPlayer1;
            }
            else if (playerNum == 2)
            {
                input = GeneralData.inputPlayer2;
            }

            // Load the previous position
            float[] pos = GeneralData.getPlayerbyNum(playerNum).pos;
            this.transform.position = new Vector3(pos[0], pos[1], pos[2]);
            if (PlayerPrefs.GetInt("Input" + playerNum) == -1)
            {
                profile = new Profile(playerNum, 0);
            }
            else
            {
                profile = new Profile(playerNum, PlayerPrefs.GetInt("Input" + playerNum));
            }

            GeneralData.setProfile(playerNum, profile);

            Light light = GetComponentInChildren <Light>();

            cam    = GameObject.Find("Main Camera").GetComponent <CameraController>();
            spirit = GameObject.FindGameObjectWithTag("Spirit").GetComponent <SpiritController>();


            // set skills form DB
            setSkills();


            attack  = GetComponent <SkillManager>().getSkill(SkillsID.HeroAttack);
            reflect = GetComponent <SkillManager>().getSkill(SkillsID.Reflect);

            animator        = GetComponent <Animator>();
            movementManager = GetComponent <MovementManager>();
            lastMove        = Vector3.zero;


            if (GeneralData.multiplayer)
            {
                multiplayer = true;
                if (playerNum == 1)
                {
                    secondPlayer.SetActive(true);
                    secondPlayerExperience.SetActive(true);
                }
                else if (playerNum == 2)
                {
                    //secondPlayer = GameObject.Find(this.transform.name.Substring(0, transform.name.Length-1)+"1");
                }
            }


            audioSource        = GetComponent <AudioSource>();
            audioSource.volume = PlayerPrefs.GetFloat("SFXVolume");

            lastMove = Vector3.zero;

            // Added by Sidney (set hurt and death reactions)
            var health = GetComponent <HealthManager>();

            health.setHurtCallback(() =>
            {
                animator.SetTrigger("hurt");
                if (hurtSound != null)
                {
                    audioSource.PlayOneShot(hurtSound);
                }
            });
            health.setDeathCallback(() =>
            {
                // Play death animation
                animator.SetTrigger("death");
                // Play death sound
                if (deathSound != null)
                {
                    audioSource.PlayOneShot(deathSound);
                }
                // End the game
                //Time.timeScale = 0;
                Cursor.visible   = true;
                Cursor.lockState = CursorLockMode.None;
                UnityEngine.SceneManagement.SceneManager.LoadScene("GameOver");
                Time.timeScale = 1f;
            });
        }