public override void TakeInput()
    {
        if (channels.target)
        {
            float d;
            Plane canvasPlane = new Plane(canvas.transform.forward, canvas.transform.position);

            Vector3 aimDir;
            bool    canPredict = SpaceUtil.PredictPosition(channels.target.body, body, proj.launchSpeed, out aimDir);

            if (canPredict)
            {
                Ray  ray = new Ray(cam.transform.position, aimDir);
                bool b   = canvasPlane.Raycast(ray, out d);

                if (b)
                {
                    transform.position = ray.GetPoint(d);
                }
            }

            Vector2 s = canvas.sizeDelta;

            Vector2 v = rect.anchoredPosition + (s / 2);

            image.enabled = v.x > 0 && v.y > 0 && v.x < s.x && v.y < s.y;
        }
        else
        {
            image.enabled = false;
        }
    }
예제 #2
0
    private void FireAtTarget()
    {
        Vector3 aim;

        if (SpaceUtil.PredictPosition(channels.target.body, self.body, projectile.launchSpeed, out aim))
        {
            channels.aim    = transform.position + aim * 1000;
            channels.firing = true;
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        body.velocity = velocity;

        if (projectile && timer.Use())
        {
            Projectile proj = Instantiate(projectile, transform.position, transform.rotation).GetComponent <Projectile>();

            Vector3 dir;
            if (SpaceUtil.PredictPosition(target, body, proj.launchSpeed, out dir))
            {
                proj.Fire(dir);
                proj.velocity += body.velocity;
            }
        }
    }