Exemple #1
0
    private Vector3?PointToFoe()
    {
        RaycastHit[] hits = Physics.SphereCastAll(this.transform.position, range, Vector3.up, 99, _layerMask);

        if (hits.Length == 0)
        {
            return(null);
        }

        TowerUtility.SortFromCenter(this.transform.position, hits);
        GameObject target    = hits[0].collider.gameObject;
        Vector3    targetPos = TowerUtility.predictedPosition(target.transform.position + Vector3.up * 0.25f, this.transform.position, target.GetComponent <NavMeshAgent>().velocity, 10f);

        return(targetPos);
    }
Exemple #2
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray          ray  = _camera.ScreenPointToRay(Input.mousePosition);
         RaycastHit[] hits = Physics.SphereCastAll(ray, _towerRadius, _maxRayDistance, _layerMask);
         if (hits.Length != 0)
         {
             TowerUtility.SortFromCenter(ray.origin, hits);
             if (hits[0].collider.gameObject.tag == "Ground" && hits.Length == 1 && _gameManager.CanPlaceTower())
             {
                 Vector3 pos = ray.GetPoint(0);
                 pos.y = 0.6f;
                 _towers1.Add(Instantiate(tower1Prefab, pos, Quaternion.identity));
                 onTowerAdded.Invoke();
             }
         }
     }
 }