public FireSide ShouldFire(Transform boat)
    {
        RaycastHit hit;
        FireSide   result         = FireSide.NONE;
        Vector3    leftDirection  = -boat.right * attackRange;
        Vector3    rightDirection = boat.right * attackRange;

        if (Physics.Raycast(boat.position, leftDirection, out hit, attackRange))
        {
            BoatAgent target = hit.transform.gameObject.GetComponent <BoatAgent>();
            if (target && target.Team == Team.PLAYER_1)
            {
                result = FireSide.LEFT;
            }
            if (debug)
            {
                Debug.DrawLine(boat.position, hit.point, Color.green, Time.deltaTime);
            }
        }
        else
        {
            if (debug)
            {
                Debug.DrawRay(boat.position, leftDirection * attackRange, Color.red, Time.deltaTime);
            }
        }
        if (Physics.Raycast(boat.position, rightDirection, out hit, attackRange))
        {
            BoatAgent target = hit.transform.gameObject.GetComponent <BoatAgent>();
            if (target && target.Team == Team.PLAYER_1)
            {
                if (result == FireSide.NONE)
                {
                    result = FireSide.RIGHT;
                }
                else
                {
                    result = FireSide.BOTH;
                }
            }
            if (debug)
            {
                Debug.DrawLine(boat.position, hit.point, Color.green, Time.deltaTime);
            }
        }
        else
        {
            if (debug)
            {
                Debug.DrawRay(boat.position, rightDirection * attackRange, Color.red, Time.deltaTime);
            }
        }
        return(result);
    }
Exemplo n.º 2
0
    void SelectWithMouse()
    {
        Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        BoatAgent  target = null;

        Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 5f);
        if (Physics.Raycast(ray, out hit, Mathf.Infinity, selectableMask))
        {
            target = hit.transform.GetComponent <BoatAgent>();

            if (target)
            {
                SelectFleet(target.flock.GetComponent <FleetController>());
                return;
            }
        }
        UnselectFleet();
    }
Exemplo n.º 3
0
    void Start()
    {
        this.boatAgent = Boat.GetComponent <BoatAgent>();
        this.recorder  = Boat.GetComponent <DataRecorder>();
        if (enabled)
        {
            Time.timeScale = 0;

            sw = new System.IO.StreamWriter(oStream);
            sr = new System.IO.StreamReader(iStream);



            lidar_writer = new FileStream("lidar.txt", FileMode.Create, FileAccess.Write, FileShare.Read);

            ultrasound_writer = new FileStream("ultrasound.txt", FileMode.Create, FileAccess.Write, FileShare.Read);
            images_writers    = new FileStream[recorder.Cameras.Length];
            for (int i = 0; i < recorder.Cameras.Length; i++)
            {
                images_writers[i] = new FileStream(i + ".png", FileMode.Create, FileAccess.Write, FileShare.Read);
            }
        }
    }