public void UpdateColision()
 {
     if (Camera.main != null)
     {
         Ray                      ray          = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
         RaycastHit[]             allHit       = Physics.RaycastAll(ray, distanceToPlace);
         bool                     hitChunk     = false;
         bool                     hitRessource = false;
         InventoryPlayer.SlotType slotType     = InventoryPlayer.Instance.getCurrentSlotType();
         foreach (var _hit in allHit)
         {
             if (slotType == InventoryPlayer.SlotType.Plant && _hit.collider.gameObject.CompareTag("Chunk"))
             {
                 hitChunk = true;
                 hit      = _hit;
             }
             if (Input.GetMouseButtonDown(0) && slotType != InventoryPlayer.SlotType.Spell && _hit.collider.gameObject.CompareTag("PlantRessource"))
             {
                 hitRessource = true;
                 hit          = _hit;
             }
         }
         if (hitChunk)
         {
             MeshCollider chunckCollider = hit.collider as MeshCollider;
             if (chunckCollider)
             {
                 targetPos = FindPointInChunck(chunckCollider);
                 Debug.DrawRay(targetPos, Vector3.up * 3, Color.green);
             }
             else
             {
                 targetPos = Vector3.zero;
             }
         }
         else
         {
             targetPos = Vector3.zero;
             Debug.DrawRay(ray.origin, ray.direction * distanceToPlace, Color.red);
             if (hitRessource)
             {
                 BoxCollider ressourceCollider = hit.collider as BoxCollider;
                 if (ressourceCollider)
                 {
                     RessourceAbstact plant = ressourceCollider.GetComponent <RessourceAbstact> ();
                     plant.Harvest();
                 }
             }
         }
     }
 }
Beispiel #2
0
 public Ressource(Vector2 _pos, RessourceAbstact _ressource)
 {
     pos       = _pos;
     ressource = _ressource;
 }