示例#1
0
 public override bool Use()
 {
     //Find all torches
     GameObject[] torches = GameObject.FindGameObjectsWithTag("Lightable");
     foreach (GameObject lightable in torches)
     {
         float distance = Vector3.Distance(lightable.transform.position, transform.position);
         if (distance < GlobalRegistry.PLAYER_REACH() * 3f)
         {
             // Light up that object
             LightableTorch lightScript = lightable.GetComponent <LightableTorch>();
             if (lightScript)
             {
                 lightScript.Light();
             }
         }
     }
     //Torches are not destroyed upon use
     return(false);
 }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (GlobalRegistry.CheckKey("PickUp"))
        {
            playerCollider.enabled = false;
            RaycastHit2D touched = Physics2D.CircleCast(
                (Vector2)playerTransform.position,
                GlobalRegistry.PLAYER_REACH(),
                playerInstance.GetDirection(),
                GlobalRegistry.PLAYER_REACH(),
                layerMask);
            playerCollider.enabled = true;
            //Pick up the object

            if (touched.collider.gameObject.GetComponent <Material>())
            {
                if (touched.collider != null)
                {
                    playerInstance.PickUp(touched.collider.gameObject);
                }
            }
        }
    }