コード例 #1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        RubyController ruby = collider.GetComponent <RubyController>();

        if (ruby)
        {
            if (ruby.currentHealth < ruby.maxHealth)
            {
                ruby.ChangeHealth(healthChange);
                Destroy(gameObject);
            }
        }
    }
コード例 #2
0
    private void OnTriggerEnter2D(Collider2D trigger)
    {
        RubyController control = trigger.GetComponent <RubyController>();

        // If Ruby enters, increase health
        if ((control != null) && (control.currentHealth < control.maxHealth))
        {
            control.ChangeHealth(1);
            Destroy(gameObject);
        }

        Debug.Log("Object that entered trigger: " + trigger);
    }
コード例 #3
0
ファイル: HealthCollectable.cs プロジェクト: FenGsHt/Tenet
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("触发的对象是" + collision);


        RubyController rubyController = collision.GetComponent <RubyController>();

        if (rubyController != null)
        {
            rubyController.ChangeHealth(1);
            Destroy(gameObject);
        }
    }
コード例 #4
0
    // Stay used to keed damaging as long as she's in the zone
    void OnTriggerStay2D(Collider2D other)
    {
        RubyController rController = other.GetComponent <RubyController>();

        if (null != rController)
        {
            if (rController.health != 0)
            {
                rController.updateHealth(-1);
                //Destroy(gameObject);
            }
        }
    }
コード例 #5
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        RubyController rubyController = other.GetComponent <RubyController>();

        if (rubyController != null && rubyController.Health < rubyController.maxHealth)
        {
            rubyController.ChangeHealth(1);
            Instantiate(collectibleEffect, transform.position, Quaternion.identity);
            Destroy(gameObject);

            rubyController.PlaySound(collectedClip);
        }
    }
コード例 #6
0
    public void Fix()
    {
        broken = false;
        rigidbody2D.simulated = false;
        animator.SetTrigger("Fixed");

        smokeEffect.Stop();

        GameObject rubyControllerObject = GameObject.FindWithTag("RubyController");

        rubyController = rubyControllerObject.GetComponent <RubyController>();
        rubyController.ChangeScore(1);
    }
コード例 #7
0
    //Public because we want to call it from elsewhere like the projectile script
    public void Fix()
    {
        broken = false;
        rigidbody2D.simulated = false;
        //optional if you added the fixed animation
        animator.SetTrigger("Fixed");

        smokeEffect.Stop();

        RubyController rubyControllerObject = GameObject.FindWithTag("RubyController").GetComponent <RubyController>();

        rubyControllerObject.ChangeScore();
    }
コード例 #8
0
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            controller.increaseAmmo();
            controller.setAmmoText();
            Destroy(gameObject);

            controller.PlaySound(cogCollectedAudio);
        }
    }
コード例 #9
0
ファイル: HealthCollectible.cs プロジェクト: emily-li/ruby
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController rubyController = other.GetComponent <RubyController>();

        if (rubyController != null)
        {
            if (rubyController.health < rubyController.maxHealth)
            {
                rubyController.ChangeHealth(1);
                Destroy(gameObject);
            }
        }
    }
コード例 #10
0
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            Destroy(gameObject);

            controller.PlaySound(bambiCollectedAudio);

            NonPlayerCharacter.hasFrog = true;
        }
    }
コード例 #11
0
ファイル: Enemy.cs プロジェクト: dbltnk/deckbuilding-shooter
    void OnCollisionStay2D(Collision2D other)
    {
        if (repaired)
        {
            return;
        }

        RubyController controller = other.collider.GetComponent <RubyController>();

        if (controller != null)
        {
            controller.ChangeHealth(-1);
        }
    }
コード例 #12
0
ファイル: HealthCollectible.cs プロジェクト: Bassadin/RubyRPG
    private void OnTriggerEnter2D(Collider2D collision)
    {
        RubyController controller = collision.GetComponent <RubyController>();

        if (controller != null)
        {
            if (controller.health < controller.startHealth)
            {
                controller.ChangeHealth(healthValue);
                Instantiate(pickupParticles, gameObject.transform.position, Quaternion.identity);
                Destroy(gameObject);
            }
        }
    }
コード例 #13
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        //获取RubyController脚本,注意脚本是挂在角色上的,也就是这里的collision。
        RubyController rubyController = collision.GetComponent <RubyController>();

        Debug.Log(rubyController);
        //对rubyController获取进行判空处理,让代码更严谨
        if (rubyController != null)
        {
            //调用血量改变参数
            rubyController.ChangeHP(-1);
            Debug.Log(rubyController.CurrentHP);
        }
    }
コード例 #14
0
    // Start is called before the first frame update
    void Start()
    {
        rigidbody2D = GetComponent <Rigidbody2D>();
        timer       = changeTime;
        animator    = GetComponent <Animator>();

        GameObject controllerObject = GameObject.FindWithTag("RubyController"); //this line of code finds the RubyController script by looking for a "RubyController" tag on Ruby

        if (controllerObject != null)

        {
            controller = controllerObject.GetComponent <RubyController>(); //and this line of code finds the rubyController and then stores it in a variable
        }
    }
コード例 #15
0
    // Start is called before the first frame update
    void Start()
    {
        rigidbody2D = GetComponent <Rigidbody2D>();
        timer       = changeTime;
        animator    = GetComponent <Animator>();

        GameObject rubyControllerObject = GameObject.FindWithTag("RubyController");

        if (rubyControllerObject != null)

        {
            rubyController = rubyControllerObject.GetComponent <RubyController>();
        }
    }
コード例 #16
0
    // it calls this OnTriggerEnter2D function on the first frame when it detects a new Rigidbody entering the Trigger
    void OnTriggerEnter2D(Collider2D other)
    {
        // if enemy collide with this it will retinr null because it is not a RubyController class
        RubyController controller = other.GetComponent <RubyController>();

        if (controller.health < controller.maxHealth)
        {
            if (controller != null)
            {
                controller.changeHealth(1);
                Destroy(gameObject);
            }
        }
    }
コード例 #17
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "player")
     {
         RubyController rubyController = other.GetComponent <RubyController>();
         if (rubyController.GetCurHp() < rubyController.m_fMaxHp)
         {
             rubyController.ChangeHp(1);
             rubyController.PlaySound(m_acPickUp);
             Instantiate(m_effectPickUp, transform.position, Quaternion.identity);
             Destroy(gameObject);
         }
     }
 }
コード例 #18
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        RubyController rc = collision.GetComponent <RubyController>();

        if (rc)
        {
            //Debug.Log("Object that entered the trigger: " + collision);
            bool needed = rc.ChangeHealth(1);
            if (needed)
            {
                Destroy(gameObject);
            }
        }
    }
コード例 #19
0
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            if (controller.health < controller.maxHealth)
            {
                controller.ChangeHealth(1);
                Destroy(gameObject);
            }
        }
        Debug.Log("Object that entered the trigger : " + other);
    }
コード例 #20
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("object that entered the trigger:" + collision);
        RubyController rubyController = collision.GetComponent <RubyController>();

        if (rubyController != null)
        {
            if (rubyController.health < rubyController.maxHealth)
            {
                rubyController.ChangeHealth(1);
                Destroy(gameObject);
            }
        }
    }
コード例 #21
0
    void OnTriggerEnter2D(Collider2D iOther)
    {
        RubyController gController = iOther.GetComponent <RubyController>();

        if (gController != null)
        {
            if (gController.gHealth < gController.cMaxHealth)
            {
                gController.ChangeHealth(1);
                Destroy(gameObject);
                gController.PlaySound(gCollectedClip);
            }
        }
    }
コード例 #22
0
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            if (controller.health < controller.maxHealth)
            {
                controller.ChangeHealth(1);
                ParticleSystem effectObject = Instantiate(collectEffect, transform.position, Quaternion.identity);
                Destroy(gameObject);
            }
        }
    }
コード例 #23
0
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            if (controller.health < controller.maxHealth)
            {
                controller.ChangeHealth(1);
                Destroy(gameObject);
                controller.PlaySound(collectedClip);
            }
        }
    }
コード例 #24
0
ファイル: DamageZone.cs プロジェクト: Edukative/Pau_Adventure
    void OnTriggerStay2D(Collider2D other)
    {
        Debug.Log("object that entred the trigger: " + other);

        RubyController controller = other.GetComponent <RubyController>(); // get the player controller from the other thing collied with trigger



        if (controller != null) // if the controller retrived is not empty
        {
            // ! the excamation is a negation value
            controller.ChangeHealth(-1); // call the health function and add 1 to the health of the player
        }
    }
コード例 #25
0
ファイル: WinningZone.cs プロジェクト: teufelz/GameProgFinal
    private void OnTriggerEnter2D(Collider2D collision)
    {
        RubyController controller = collision.GetComponent <RubyController>();

        if (controller != null)
        {
            // winning
            Debug.Log("win");
            MissionPassContainer.SetActive(true);

            // pause game use 1 to run game again
            Time.timeScale = 0;
        }
    }
コード例 #26
0
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController rubyController = other.GetComponent <RubyController>();

        if (rubyController != null)
        {
            if (rubyController.Lövedék < rubyController.maxLövedék)
            {
                rubyController.ChangeAmmo(LövedékDB);
                Destroy(gameObject);
                rubyController.PlaySound(collectedClip);
            }
        }
    }
コード例 #27
0
    private void OnTriggerStay2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            //if(controller.health <= controller.maxHealth)
            //{
            controller.ChangeHealth(-1);
            //Destroy(gameObject);
            Debug.Log($"damage zone health: {controller.health}");
            //}
        }
    }
コード例 #28
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        RubyController controller = collision.GetComponent <RubyController>();

        if (controller != null)
        {
            if (controller.CurrentHealth < controller.MaxHealth)
            {
                controller.ChangeHealth(25);
                Destroy(gameObject);

                controller.PlaySound(collectedClip);
            }
        }
    }
コード例 #29
0
ファイル: Speed.cs プロジェクト: Almond17/FinalGame
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            //if (controller.health < controller.maxHealth)
            //{
            controller.addspeed();
            Destroy(gameObject);

            //controller.PlaySound(collectedClip);
            //}
        }
    }
コード例 #30
0
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent <RubyController>();

        if (controller != null)
        {
            if (controller.health < controller.maxHealth)
            {
                controller.ChangeHealth(1);
                Destroy(gameObject);
                controller.PlaySound(collectedClip);
                GameObject HealthParticle = Instantiate(HealthPrefab, transform.position, Quaternion.identity);
            }
        }
    }