Esempio n. 1
0
    private Vector2 DirectuinForEnemy(IntarectableObject enemy, out Vector2Int tempNewPosition)
    {
        pathfinding.SetIntactableObjects(GetIntarectalePositoin3Int());
        List <Vector2Int> path;

        path = pathfinding.FindPath(enemy.Position, player.Position);


        if (path == null)
        {
            tempNewPosition = (Vector2Int)map.WorldToCell(enemy.Position);
            return(new Vector2(0, 0));
        }
        else
        {
            tempNewPosition = path[0];
        }
        Vector2Int vector2 = (Vector2Int)map.WorldToCell(enemy.Position);
        //Debug.Log(path);

        Vector2 directionForEnemy = (Vector2)(path[0] - vector2);

        //Debug.Log("map.WorldToCell(intarectableObjects[i].Position  " +
        //   map.WorldToCell(intarectableObjects[i].Position) +
        //   "path[0]  " + path[0]);

        //Debug.Log(directionForEnemy);

        if (directionForEnemy.x > 0)
        {
            directionForEnemy.x = (directionForEnemy.x - 0.5f);
            //Debug.Log(directionForEnemy.x);
        }
        if (directionForEnemy.x < 0)
        {
            directionForEnemy.x = (directionForEnemy.x + 0.5f);
        }
        if (directionForEnemy.y > 0)
        {
            directionForEnemy.y = (directionForEnemy.y - 0.5f);
        }
        if (directionForEnemy.y < 0)
        {
            directionForEnemy.y = (directionForEnemy.y + 0.5f);
        }
        return(directionForEnemy);
    }
Esempio n. 2
0
 public void DeleteIntarectale(IntarectableObject intarectableObject)
 {
     Destroy(intarectableObject.gameObject);
     intarectableObjects.Remove(intarectableObject);
 }
Esempio n. 3
0
 public void RemoveIntarectable(IntarectableObject intarectableObject)
 {
     intarectableObjects.Remove(intarectableObject);
 }
Esempio n. 4
0
 public void AddIntarectable(IntarectableObject intarectableObject)
 {
     intarectableObjects.Add(intarectableObject);
 }
Esempio n. 5
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     targetIntarectable = null;
 }
Esempio n. 6
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     targetIntarectable = collision.GetComponent <IntarectableObject>();
     targetIntarectable.TakeHit(damage);
 }