Beispiel #1
0
    public IEnumerator AutomatedShoot()
    {
        ShipClass target = null;
        Rigidbody rb     = null;

        if (shipClass.Fleet.Enemies.Count < 1)
        {
            useTargettingSystem = false;
            yield break;
        }

        int random = Random.Range(0, shipClass.Fleet.Enemies.Count - 1);

        if (shipClass.Fleet != null)
        {
            target = shipClass.Fleet.Enemies[random];
            rb     = target.GetComponent <Rigidbody>();
        }

        while (target != null && transform != null && target.Alive && shipClass.Alive)
        {
            float   distance = Vector3.Distance(transform.position, target.transform.position);
            float   time     = distance / 600f;
            Vector3 lead     = rb.velocity * time;

            weapons.Target(target.transform.position + lead);
            weapons.Fire(target.transform.position + lead);
            yield return(new WaitForSeconds(0.025f));
        }

        StartCoroutine(AutomatedShoot());
        yield return(null);
    }
Beispiel #2
0
    private void MouseInput()
    {
        if (weapons == null)
        {
            return;
        }

        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        Vector3    point;

        if (Physics.Raycast(ray, out hit, 20000F))
        {
            point      = hit.point;
            lastKnownZ = hit.point.z;
        }
        else
        {
            Vector3 screen = Input.mousePosition;
            screen.z = lastKnownZ;
            point    = camera.ScreenToWorldPoint(screen);
            //Debug.DrawLine(camera.transform.position, point, Color.red, 5f);
        }

        weapons.Target(point);

        if (Input.GetMouseButtonDown(1))
        {
            weapons.Fire(point);
        }
    }