示例#1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        // if it's a collectable, we miss it
        if (other.GetComponent <Collectable>() != null)
        {
            scoreTracker.AddMissed();
            soundPlayer.PlayMissSound();
            BoxCollider2D playerCollider = transform.root.GetComponent <BoxCollider2D>();

            // Get the closest point on the player collider to the
            // collectable's position and show miss text there
            Vector3 missTextPosition = playerCollider.ClosestPoint(other.GetComponent <Transform>().position);
            missTextPosition.y += 3; // add vertical offset so it isn't too low
            Instantiate(MissText, missTextPosition, Quaternion.identity);
        }
    }