Ejemplo n.º 1
0
    //void FixedUpdate()
    //{
    //    timer += Time.fixedDeltaTime;

    //    if (player == null) return;
    //    float dist = Vector3.Distance(player.transform.position, transform.position);

    //    if (dist > attackRange)
    //    {
    //        transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
    //    }

    //    transform.LookAt(player.transform.position);

    //    if (timer > shootCoolDown)
    //    {
    //        tw.Shoot();
    //        timer = 0f;
    //    }
    //}

    void Update()
    {
        //timer += Time.fixedDeltaTime;

        if (enemy == null)
        {
            SearchEnemy();
            return;
        }
        float dist = Vector3.Distance(enemy.transform.position, transform.position);

        if (dist > curSD)
        {
            nam.SetDestination(enemy.transform.position);
        }
        else
        {
            nam.ResetPath();
            //transform.LookAt(enemy.transform.position);
            Vector3    dir            = enemy.transform.position - transform.position;
            Quaternion wantedRotation = Quaternion.LookRotation(dir);
            transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, rotateSpeed * Time.deltaTime);
            //if (timer > shootCoolDown)
            //{
            //    timer = 0f;
            //}
        }
        if (dist < curAR)
        {
            tw.Shoot();
        }
    }
Ejemplo n.º 2
0
    void FixedUpdate()
    {
        float horizontal = Input.GetAxis("HorizontalUI");
        float vertical   = Input.GetAxis("VerticalUI");

        transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime * vertical);
        transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime * horizontal);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            tw.Shoot();
        }

        //if (Input.GetKey(KeyCode.W))
        //{
        //    transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
        //}
        //if (Input.GetKey(KeyCode.S)) {
        //    transform.Translate(Vector3.forward * -moveSpeed * Time.deltaTime);
        //}
        //if (Input.GetKey(KeyCode.A))
        //{
        //    transform.Rotate(Vector3.up * -rotateSpeed * Time.deltaTime);
        //}
        //if (Input.GetKey(KeyCode.D))
        //{
        //    transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime);
        //}
    }