コード例 #1
0
    public void SpawnStatChangeText(int value, Sprite icon = null)
    {
        ShipStatsUI shipStatsUI  = shipStats.GetComponent <ShipStatsUI>();
        GameObject  statChangeUI = Instantiate(shipStatsUI.statChangeText);

        RectTransform rect = statChangeUI.GetComponent <RectTransform>();

        Vector3 spawnPos = cam.WorldToScreenPoint(transform.GetChild(0).position);

        rect.anchoredPosition = new Vector2(spawnPos.x, spawnPos.y);

        statChangeUI.transform.parent = shipStats.GetComponent <ShipStatsUI>().canvas; // you have to set the parent after you change the anchored position or the position gets messed up.  Don't set it in the instantiation.  I don't know why someone decided to change that.

        MoveAndFadeBehaviour moveAndFadeBehaviour = statChangeUI.GetComponent <MoveAndFadeBehaviour>();

        moveAndFadeBehaviour.offset = new Vector2(0, 25 + transform.GetChild(0).localPosition.y * 100);
        moveAndFadeBehaviour.SetValue(value, icon);
    }
コード例 #2
0
    private void Awake()
    {
        // Singleton pattern that makes sure that there is only one MoraleManager
        if (instance)
        {
            Destroy(gameObject);
        }
        else
        {
            instance = this;
        }

        shipStatsUI = FindObjectOfType <ShipStatsUI>();
        ship        = GameObject.FindObjectOfType <ShipStats>();
        if (!ship)
        {
            print("Could not find ship");
        }
    }
コード例 #3
0
 private void Awake()
 {
     shipStatsUI = GetComponent <ShipStatsUI>();
     tick        = FindObjectOfType <Tick>();
     cStats      = gameObject.GetComponent <CharacterStats>();
 }