Exemplo n.º 1
0
    public static void CreatDamageText(string str, Transform position, int DMGtype)
    {
        DamageText exp = Instantiate(damageText);

        if (exp != null)
        {
            exp.transform.SetParent(canv.transform, false);
            exp.GetComponent <RectTransform>().position = Camera.main.WorldToScreenPoint(position.position);
            exp.SetText(str);
            switch (DMGtype)
            {
            case 1:
                exp.GetComponentInChildren <Animator>().SetTrigger(Random.Range(0, 10) > 5 ? "Cri1": "Cri2");
                break;

            case 2:
                exp.GetComponentInChildren <Animator>().SetTrigger(Random.Range(0, 10) > 5 ? "DMG1":"DMG2");
                break;

            case 3:
                exp.GetComponentInChildren <Animator>().SetTrigger(Random.Range(0, 10) > 5 ? "Dot1":"Dot2");
                break;
            }
        }
    }
Exemplo n.º 2
0
    public void ShowDmgText(Vector3 pos, float dmg, int type, bool isReinforced)
    {
        GameObject text = GameManager.Inst().ObjManager.MakeObj("DamageText");

        text.transform.position = pos;
        text.SetActive(true);
        DamageText dmgText = text.GetComponent <DamageText>();

        if (type == (int)DamageType.PLAYERHEAL)
        {
            dmgText.SetPlusText(dmg);
        }
        else
        {
            dmgText.SetText(dmg);
        }
        dmgText.SetSize(dmgText.DefaultSize);
        dmgText.SetColor(type);

        if (isReinforced)
        {
            //text.transform.localScale = Vector3.one * 2.0f;
            dmgText.SetSize(48);
            dmgText.SetColor((int)DamageType.REINFORCED);
        }

        ActivationTimer timer = text.GetComponent <ActivationTimer>();

        timer.IsStart = true;
    }
Exemplo n.º 3
0
        public void DisplayCustomTextAbove(CombatEntity entity, string text,
                                           bool bUseUnscaleTime = true, Color customColor = default(Color), int fontSize = -1)
        {
            if (_dmgTextPrefab == null)
            {
                _dmgTextPrefab = Resources.Load <GameObject>("Prefab/DamageText");
            }

            entity.FindCharacterSprite();
            if (entity.CharacterSprite != null)
            {
                Vector2 rendererPosition = entity.CharacterSprite.RendererPosition;
                rendererPosition.y += 1.8f;
                GameObject gameObject = UnityEngine.Object.Instantiate(_dmgTextPrefab, rendererPosition, Quaternion.identity);
                DamageText damageText = gameObject.GetComponent <DamageText>();
                damageText.SetText(text);
                if (customColor.a > 0f)
                {
                    damageText.SetColor(customColor);
                }
                if (fontSize >= 0)
                {
                    damageText.SetSize(fontSize);
                }
                if (!bUseUnscaleTime)
                {
                    gameObject.GetComponentInChildren <UI2DFloatyText>()._useUnscaleTime = false;
                    return;
                }
            }
            else
            {
                Debug.LogError("Missing CharacterSprite");
            }
        }
    public static void makeDamageText(string text, Transform location, float time, string type)  //this is the function that players and enemies can call to create damage text wherever they desire
    {
        dth.StartCoroutine("textOfDamage", time);
        DamageText tempDamageText = null;

        switch (type)
        {
        case "Enemy":
            Debug.Log("Enemy thing selected");
            tempDamageText = Instantiate(dth.damageTextEnemy);
            break;

        case "Player":
            tempDamageText = Instantiate(dth.damageText);
            break;

        case "Heal":
            tempDamageText = Instantiate(dth.healText);
            break;
        }


        GameObject canvas         = GameObject.Find("Canvas");
        Vector2    screenPosition = Camera.main.WorldToScreenPoint(location.position);

        tempDamageText.transform.SetParent(canvas.transform, false);
        tempDamageText.SetText(text);
        tempDamageText.transform.position = screenPosition;
    }
Exemplo n.º 5
0
    public static void CreateDamageText(int damage, float x, float y)
    {
        DamageText instance       = Instantiate(damageText);
        Vector2    screenPosition = Camera.main.WorldToScreenPoint(new Vector2(x, y));

        instance.transform.SetParent(canvas.transform, false);
        instance.transform.position = screenPosition;
        if (damage < 0) //Healing
        {
            instance.SetColor(Color.green);
            instance.SetText((-damage).ToString());
        }
        else
        {
            instance.SetText(damage.ToString());
        }
    }
    public static void CreateDamageText(string text, Transform location, Color textColor)
    {
        DamageText instance = Instantiate(damageText);

        instance.transform.position = Camera.main.WorldToScreenPoint(location.position + Vector3.up);
        instance.transform.SetParent(canvas.transform, false);
        instance.SetText(text, textColor);
        instance.sourcePosition = location;
    }
Exemplo n.º 7
0
    public static void CreateDamageText(string text, Transform location)
    {
        DamageText instance       = Instantiate(popupText);
        Vector2    screenPosition = Camera.main.WorldToScreenPoint(location.position);

        instance.transform.SetParent(canvas.transform, false);
        instance.transform.position = screenPosition;
        instance.SetText(text);
    }
Exemplo n.º 8
0
    public static void CreateDamageText(string text, Transform location)
    {
        DamageText instance  = Instantiate(DamageText);
        Vector2    screenPos = Camera.main.WorldToScreenPoint(new Vector2(location.position.x + Random.Range(-5, 9), location.position.y));

        // Vector2 screenPosition = Camera.main.ScreenToWorldPoint(location.position);
        instance.transform.SetParent(canvas.transform, false);
        instance.transform.position = location.position;

        instance.SetText(text);
    }
Exemplo n.º 9
0
    //this is the final calculated value of damage
    public void ReceiveDamage(float _damage)
    {
        DamageText damage_text = Instantiate(Resources.Load <DamageText>("Prefabs/DamageText"));

        damage_text.transform.position = transform.position + new Vector3(0, 5, 0);

        if (_damage < 0)
        {
            //miss
            damage_text.SetText("MISS");
            return;
        }
        int rounded_damage = Mathf.RoundToInt(_damage);

        health -= rounded_damage;
        damage_text.SetText("-" + rounded_damage.ToString());
        Debug.Log(name + " took " + rounded_damage + " damage");
        if (health <= 0)
        {
            Debug.Log(name + " fainted");
            Delete();
        }
    }
Exemplo n.º 10
0
 public void ReceiveHealing(int _healing)
 {
     if (_healing + health > HP)
     {
         _healing = HP - health;
     }
     health += _healing;
     if (_healing > 0)
     {
         DamageText healing_text = Instantiate(Resources.Load <DamageText>("Prefabs/DamageText"));
         healing_text.GetComponent <TextMesh>().color = Color.green;
         healing_text.transform.position = transform.position + new Vector3(0, 5, 0);
         healing_text.SetText("+" + _healing.ToString());
         Debug.Log(name + " healed " + _healing);
     }
 }
Exemplo n.º 11
0
 public void OnCharacterDamaged(CharacterDamagedEvent damagedEvent)
 {
     if (DamageText != null)
     {
         Vector3    randOffset    = new Vector3(Random.Range(0f, RandOffset.x), Random.Range(0f, RandOffset.y), 0);
         GameObject damageTextObj = Instantiate(
             DamageText,
             damagedEvent.Position + new Vector3(Offset.x, Offset.y, 0) + randOffset,
             Quaternion.identity
             );
         DamageText     damageText = damageTextObj.GetComponentInChildren <DamageText>();
         VertexGradient gradient   = damagedEvent.CharacterType == AllyType.Friendly ?
                                     new VertexGradient(topAllyColour, topAllyColour, botAllyColour, botAllyColour) :
                                     new VertexGradient(topEnemyColour, topEnemyColour, botEnemyColour, botEnemyColour);
         damageText.SetText(damagedEvent.Damage.ToString(), gradient);
     }
 }
Exemplo n.º 12
0
    public void Heal(float health)
    {
        currentHealth = Mathf.Min(currentHealth + health, MaxHealth);
        FlashGreen();

        if (HealFX)
        {
            Instantiate(HealFX, this.transform);
        }

        GameObject ht     = (GameObject)Instantiate(damageTextPrefab, this.gameObject.transform.position, Camera.main.transform.rotation);
        DamageText script = ht.gameObject.GetComponent <DamageText>();

        script.SetColor(Color.green);
        script.SetText(Mathf.Round(health).ToString());

        UpdateHealthUI();
    }
Exemplo n.º 13
0
    public virtual void TakeDamage(float damage, bool isCriticalHit)
    {
        if (currentHealth - damage > 0)
        {
            currentHealth = Mathf.Max(currentHealth - damage, 0);
            FlashRed();

            GameObject dt     = (GameObject)Instantiate(damageTextPrefab, this.gameObject.transform.position + Vector3.up * this.gameObject.transform.localScale.y / 2, Camera.main.transform.rotation);
            DamageText script = dt.gameObject.GetComponent <DamageText>();
            if (isCriticalHit)
            {
                script.SetColor(Color.blue);
            }
            script.SetText(Mathf.Round(damage).ToString());
        }
        else
        {
            Die();
        }

        UpdateHealthUI();
    }