protected void BaseStart()
    {
        //this may eventually be extended by specific unit extensions
        use = new UnitStateExecutor(this);

        spriteRenderer = gameObject.GetComponent <SpriteRenderer> ();
        animator       = gameObject.GetComponent <Animator> ();
        audioSource    = gameObject.GetComponent <AudioSource> ();

        //add a health bar
        if (healthBarPrefab != null)
        {
            //healthBarPrefab.gameObject = gameObject;

            GameObject gui = GameObject.FindGameObjectWithTag("GuiManager");
            //GameObject healthBarPrefab = GameObject.FindGameObjectWithTag ("HealthBar");

            healthBar = (Transform)Instantiate(healthBarPrefab, transform.position, transform.rotation);
            if (healthBar != null)
            {
                healthBar.name   = "HealthBar";
                healthBar.parent = gui.transform;

                healthBar.GetComponent <dfFollowObject> ().mainCamera = Camera.main;
                healthBar.GetComponent <dfFollowObject> ().attach     = gameObject;
                healthBar.GetComponent <dfFollowObject> ().enabled    = true;

                healthBar.GetComponentInChildren <dfProgressBar> ().MaxValue = lifePoints;
                healthBar.GetComponentInChildren <dfProgressBar> ().Value    = lifePoints;

                dfPanel dfp = healthBar.GetComponent <dfPanel> ();
                dfp.IsVisible = false;
            }
            else
            {
                Debug.Log("could not instantiate");
            }
        }

        statesSupported = new List <int> (new int[] {
            StateIdle,
            StateSelected,
            StateAdvancing,
            StateMelee,
            StateDead
        });

        BattleSceneManager.s.units.Add(this);

        SetState(StateIdle);

        BattleSceneManager.s.OnUnitClick += OnUnitClick;
    }
Esempio n. 2
0
    protected void BaseStart()
    {
        //this may eventually be extended by specific unit extensions
        use = new UnitStateExecutor (this);

        spriteRenderer = gameObject.GetComponent<SpriteRenderer> ();
        animator = gameObject.GetComponent<Animator> ();
        audioSource = gameObject.GetComponent<AudioSource> ();

        //add a health bar
        if (healthBarPrefab != null) {

            //healthBarPrefab.gameObject = gameObject;

            GameObject gui = GameObject.FindGameObjectWithTag ("GuiManager");
            //GameObject healthBarPrefab = GameObject.FindGameObjectWithTag ("HealthBar");

            healthBar = (Transform)Instantiate (healthBarPrefab, transform.position, transform.rotation);
            if (healthBar != null) {

                healthBar.name = "HealthBar";
                healthBar.parent = gui.transform;

                healthBar.GetComponent<dfFollowObject> ().mainCamera = Camera.main;
                healthBar.GetComponent<dfFollowObject> ().attach = gameObject;
                healthBar.GetComponent<dfFollowObject> ().enabled = true;

                healthBar.GetComponentInChildren<dfProgressBar> ().MaxValue = lifePoints;
                healthBar.GetComponentInChildren<dfProgressBar> ().Value = lifePoints;

                dfPanel dfp = healthBar.GetComponent<dfPanel> ();
                dfp.IsVisible = false;

            } else
                Debug.Log ("could not instantiate");
        }

        statesSupported = new List<int> (new int[] {
            StateIdle,
            StateSelected,
            StateAdvancing,
            StateMelee,
            StateDead
        });

        BattleSceneManager.s.units.Add (this);

        SetState (StateIdle);

        BattleSceneManager.s.OnUnitClick += OnUnitClick;
    }