示例#1
0
    public IEnumerator attribute_Test_update_gold_WithEnumeratorPasses()
    {
        UnityEngine.SceneManagement.SceneManager.LoadScene("Untitled");
        SetCharacter.istest = true;
        yield return(null);

        /// init GameObject
        GameObject enemy = SetCharacter.enemy;

        Assert.AreNotEqual(enemy, null);
        enemy.transform.position = new Vector3(12, 0, 15);
        enemy.transform.rotation = Quaternion.identity;

        /// init script test
        yield return(null);

        attribute testcs = enemy.GetComponent <attribute> ();

        Assert.IsTrue(testcs.ifAlive);

        /// test update_gold
        testcs.gold = 100f;
        testcs.update_gold(100f);
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.gold - 200f));
        testcs.update_gold(-3f);
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.gold - 197f));
        testcs.update_gold(-300f);
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.gold));

        SetCharacter.istest = false;
    }
示例#2
0
    public void OnTriggerEnter(Collider colli)
    {
        attribute colli_attribute = colli.gameObject.GetComponent <attribute> ();

        if (colli.gameObject == null || colli_attribute == null)
        {
            return;
        }
        // player can get the goods
        if (colli_attribute.if_Player && type == "HP+")
        {
            colli_attribute.update_HP(value);
            Destroy(this.gameObject);
        }
        if (colli_attribute.if_Player && type == "GOLD+")
        {
            colli_attribute.update_gold(value);
            Destroy(this.gameObject);
        }
    }