Пример #1
0
 private void Start()
 {
     coinBehavior = GetComponent <CoinBehavior>();
     initColor    = GetComponent <Image>().color;
     cg           = GetComponent <CanvasGroup>();
     cg.alpha     = 0.8f;
 }
Пример #2
0
    public CoinBehavior Check(Ray ray)
    {
        // Proyectar un rayo que busca solo en la capa Items
        if (Physics.Raycast(ray, out RaycastHit itemHoverHit, _layerMaskItems))
        {
            // Pedir el componente CoinBehavior a cualquier cosa contra lo que haya pegado el rayo
            CoinBehavior selectedCoin = itemHoverHit.collider.GetComponent <CoinBehavior>();

            // Si el componente CoinBehavior fue encontrado
            if (selectedCoin != null)
            {
                // Revisar si se encontraba en la distancia minima para seleccionar
                if (Vector3.Distance(transform.position, selectedCoin.transform.position) < _collectionRadius)
                {
                    // Retornar la moneda encontrada
                    return(selectedCoin);
                }
            }
        }

        return(null);
    }
Пример #3
0
 void OnTriggerEnter(Collider other)
 {
     if (!gameIsOver)
     {
         string otherTag = other.gameObject.tag;
         // Vetor que aponta *DESTE* objeto (this) *PARA* o com qual colidiu (other)
         // http://docs.unity3d.com/Manual/DirectionDistanceFromOneObjectToAnother.html
         Vector3 heading = other.transform.position - this.transform.position;
         Debug.Log("Direction" + heading.ToString());
         Debug.Log("Distance" + heading.sqrMagnitude);             // Distancia simples, sem raiz inversa para agilizar o processo
         bool isUnderPlayer = heading.y < -0.1f && Mathf.Abs(heading.x) < other.bounds.size.x - 0.1f;
         if (otherTag.Equals("Platform") && isUnderPlayer)
         {
             Jump();
         }
         else if (otherTag.Equals("Coin"))
         {
             CoinBehavior coinBehavior = (CoinBehavior)other.gameObject.GetComponent <CoinBehavior>();
             var          coin         = coinBehavior.Pegar();
             if (coin != null)
             {
                 if (pickups.Select(po => po.Type).Contains(coin.Type))
                 {
                     var coinPickup = pickups.Find(po => po.Type == PickupType.Coin);
                     coinPickup.Quantity += coin.Quantity;
                 }
                 else
                 {
                     pickups.Add(coin);
                 }
             }
         }
         else if (otherTag.Equals("Enemy"))
         {
             GameOver();
         }
     }
 }
 // Start is called before the first frame update
 void Start()
 {
     _parentParams = GetComponentInParent <CoinBehavior>();
     // Get the vertical thrust offset to remove, from the coin body cylinder's offset relative to the parent.
     _coinOffsetFromOrigin = transform.parent.GetComponentInChildren <CoinBodyBehavior>().transform.localPosition;
 }