void FlyToEnemy()
    {
        if (Vector3.Dot(transform.position - enemy.position, transform.forward) > 0)
        {
            if (Vector3.Distance(transform.position, enemy.position) > 50f)
            {
                flyOver = false;
            }
            else
            {
                flyOver = true;
            }
        }
        if (!flyOver)
        {
            if (!fighter)
            {
                DIY_Movement.SoftLookAt(this.gameObject, enemy.position + randomVector * 3f * enemy.transform.localScale.x, rotSen);
            }
            else
            {
                DIY_Movement.SoftLookAt(this.gameObject, enemy.position, rotSen);
            }
        }
        else
        {
            DIY_Movement.SoftLookAt(this.gameObject, transform.position + (transform.position - enemy.position), rotSen);
        }

        speed = maxSpeed * 0.8f;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())

        for (int i = enemies.Count - 1; i >= 0; i--)
        {
            if (enemies[i] == null)
            {
                enemies.Remove(enemies[i]);
                i--;
            }
        }
        //mobile
        if (Input.touchCount > 0)
        {
            if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {//mobile end
                Debug.Log("not UI");
                int i = 0;
                for (i = 0; i < enemies.Count; i++)
                {
                    if (Vector2.Distance(Input.GetTouch(0).position, Camera.main.WorldToScreenPoint(enemies[i].transform.position)) < 60f)
                    {
                        enemy = enemies[i].transform;
                        if (aimIcon == null)
                        {
                            Destroy(GameObject.Find("AimIcon(Clone)"));
                            aimIcon = Instantiate(aimIconPre, GameObject.Find("EffectCanvas").transform);
                        }
                        break;
                    }
                }
                if (i == enemies.Count)
                {
                    Destroy(aimIcon);
                    enemy = null;
                }
            }
        }

        if (enemy != null)
        {
            if (Vector3.Dot(transform.forward, enemy.position - transform.position) > 0)
            {
                aimIcon.GetComponent <RectTransform>().localScale = Vector3.one;
                aimIcon.GetComponent <RectTransform>().position   = Camera.main.WorldToScreenPoint(enemy.position);
            }
            else
            {
                aimIcon.GetComponent <RectTransform>().localScale = Vector3.zero;
            }
            DIY_Movement.SoftLookAt(this.gameObject, enemy.position, aimSpeed);
        }
        else
        {
            Destroy(aimIcon);
        }
    }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (target == null)
     {
         Destroy(this.gameObject);
     }
     else
     {
         transform.Translate(0, 0, speed * Time.deltaTime);
         DIY_Movement.SoftLookAt(this.gameObject, target.position, 50);
     }
 }
    void Shoot()
    {
        // Reset the timer.
        timer = 0f;

        //rotate body

        DIY_Movement.SoftLookAt(parent.gameObject, player.position, 30f);



        // Play the gun shot audioclip.
        gunAudio.Play();

        // Enable the lights.
        gunLight.enabled = true;

        // Stop the particles from playing if they were, then start the particles.
        gunParticles.Stop();
        gunParticles.Play();

        // Enable the line renderer and set it's first position to be the end of the gun.
        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        // Perform the raycast against gameobjects on the shootable layer and if it hits something...
        if (Physics.Raycast(shootRay, out shootHit, range))
        {
            // Try and find an EnemyHealth script on the gameobject hit.
            ThiefHealth playerHealth = shootHit.collider.GetComponent <ThiefHealth>();

            // If the EnemyHealth component exist...
            if (playerHealth != null)
            {
                // ... the enemy should take damage.
                playerHealth.TakeDamage(damagePerShot);
            }

            // Set the second position of the line renderer to the point the raycast hit.
            gunLine.SetPosition(1, shootHit.point);
        }
        // If the raycast didn't hit anything on the shootable layer...
        else
        {
            // ... set the second position of the line renderer to the fullest extent of the gun's range.
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
            parent.GetComponent <MechMovement>().lostTarget = true;
        }
    }
 void MoveToDestination()
 {
     if (Vector3.Distance(transform.position, destination) > 30f)
     {
         DIY_Movement.SoftLookAt(this.gameObject, destination, 5f);
         if (Vector3.Angle(transform.forward, destination - transform.position) > 5f)
         {
             return;
         }
         speed = Mathf.Lerp(speed, maxSpeed, 0.01f);
         transform.position = transform.position + speed * transform.forward * Time.deltaTime;
     }
     else
     {
         speed = Mathf.Lerp(speed, 0f, 0.01f);
         transform.position = transform.position + speed * transform.forward * Time.deltaTime;
     }
 }
 void FireToEnemy()
 {
     for (int i = enemies.Count - 1; i >= 0; i--)
     {
         if (enemies[i] == null)
         {
             enemies.Remove(enemies[i]);
         }
         i--;
     }
     if (enemies.Count > 0)
     {
         foreach (NewFire gun in gunsUp)
         {
             if (enemyTarget[0] != null)
             {
                 gun.firing = true;
                 DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, enemyTarget[0].transform.position, 10f);
             }
             else
             {
                 gun.firing = false;
             }
         }
         foreach (NewFire gun in gunsDown)
         {
             if (enemyTarget[1] != null)
             {
                 gun.firing = true;
                 DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, enemyTarget[1].transform.position, 10f);
             }
             else
             {
                 gun.firing = false;
             }
         }
         foreach (NewFire gun in gunsLeft)
         {
             if (enemyTarget[2] != null)
             {
                 gun.firing = true;
                 DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, enemyTarget[2].transform.position, 10f);
             }
             else
             {
                 gun.firing = false;
             }
         }
         foreach (NewFire gun in gunsRight)
         {
             if (enemyTarget[3] != null)
             {
                 gun.firing = true;
                 DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, enemyTarget[3].transform.position, 10f);
             }
             else
             {
                 gun.firing = false;
             }
         }
     }
     else
     {
         foreach (NewFire gun in gunsUp)
         {
             gun.firing = false;
             DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, gun.gunEnd.position + gun.gunEnd.up * transform.localScale.x, 10f);
         }
         foreach (NewFire gun in gunsDown)
         {
             gun.firing = false;
             DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, gun.gunEnd.position - gun.gunEnd.up * transform.localScale.x, 10f);
         }
         foreach (NewFire gun in gunsLeft)
         {
             gun.firing = false;
             DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, gun.gunEnd.position - gun.gunEnd.right * transform.localScale.x, 10f);
         }
         foreach (NewFire gun in gunsRight)
         {
             gun.firing = false;
             DIY_Movement.SoftLookAt(gun.gunEnd.gameObject, gun.gunEnd.position + gun.gunEnd.right * transform.localScale.x, 10f);
         }
     }
 }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (!docking)
        {
            if (tag == "Player")
            {
                target = null;
                if (tractorBeam != null)
                {
                    Destroy(tractorBeam);
                    tractorBeam = null;
                }
            }
            wpsIndex = 0;
            if (transform.parent != null)
            {
                if (transform.parent.gameObject.tag != "KeepPlayer" && tag == "Player")
                {
                    transform.parent = GameObject.Find("KeepPlayer").transform;
                }
            }
        }
        if (docking)
        {
            if (!target)                                                                         //docking第一次为true时执行
            {
                Collider[] targetsColliders = Physics.OverlapSphere(transform.position, radius); //获取范围内可能可对接物体
                float      temp_distance    = radius;
                for (int i = 0; i < targetsColliders.Length; i++)
                {
                    if (targetsColliders[i].gameObject.tag == "Dock" || targetsColliders[i].gameObject.tag == "Part")     //对接物体的tag应设为"Dock"
                    {
                        if (Vector3.Distance(transform.position, targetsColliders[i].transform.position) < temp_distance) //获取最近Dock
                        {
                            target        = targetsColliders[i].gameObject;
                            temp_distance = Vector3.Distance(transform.position, targetsColliders[i].transform.position);
                        }
                    }
                }
                if (target)
                {
                    //清除惯性导致的速度
                    if (this.gameObject.GetComponent <Rigidbody>() != null)
                    {
                        this.gameObject.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0);
                    }
                }
            }

            if (target)
            {//如果有可对接物体
                if (gameObject.tag == "Player" && tractorBeam == null)
                {
                    tractorBeam = Instantiate(tractorBeamPre, gameObject.transform);
                }
                if (tractorBeam != null)
                {
                    tractorBeam.GetComponent <Transform>().Find("LightningEnd").gameObject.transform.position = target.transform.position;
                }
                GameObject thisTarget = target.GetComponent <Dock>().wps[wpsIndex];//当前驶向的路径点
                if (thisTarget.GetComponent <WayPoint>() == null)
                {
                    Debug.Log("好吧,你忘记给路径点加脚本了,现在看下到底漏了哪个");
                    Debug.Log("null:    " + thisTarget);
                    Debug.Log("index:   " + wpsIndex);
                    Debug.Log("target:   " + target);
                }

                if (!thisTarget.GetComponent <WayPoint>().turn)//若WayPoint的turn为false,平移至此路径点
                {
                    if (gameObject.tag == "Player")
                    {
                        gameObject.GetComponent <Flight>().stabZ = true;
                        if (target.GetComponent <DockGuide>() != null)
                        {
                            //transform.eulerAngles = Vector3.Lerp (transform.eulerAngles, target.transform.eulerAngles,3*Time.deltaTime);
                            //transform.eulerAngles = target.transform.eulerAngles;
                            //transform.localEulerAngles = Vector3.Slerp (transform.localEulerAngles, target.transform.localEulerAngles,);
                            //DIY_Movement.SoftLookAt(this.gameObject,thisTarget.transform.position,30);

                            float angle    = Vector3.Angle(transform.forward, target.transform.forward);
                            float needTime = angle / 30;
                            float v        = 1;
                            if (needTime > Mathf.Epsilon)
                            {
                                v = Time.deltaTime / needTime;
                            }
                            Quaternion t = Quaternion.Euler(0, 0, 0);
                            transform.localRotation = Quaternion.Slerp(transform.localRotation, t, v);
                        }

                        transform.Translate(Vector3.Normalize(thisTarget.transform.position - transform.position) * speed * Time.deltaTime);
                        //Debug.Log("docking to" + thisTarget);
                    }
                    else
                    {
                        Vector3 offset = (thisTarget.transform.position - transform.position).normalized;
                        float   angle  = Vector3.Angle(transform.forward, offset);
                        if (angle > Mathf.Epsilon)
                        {
                            DIY_Movement.SoftLookAt(this.gameObject, thisTarget.transform.position, 30);
                        }
                        else
                        {
                            transform.Translate(Vector3.forward * speed * Time.deltaTime);
                        }
                    }
                }
                else
                {//之前的其他路径点则先转向,后直行
                    Vector3 offset = (thisTarget.transform.position - transform.position).normalized;
                    float   angle  = Vector3.Angle(transform.forward, offset);
                    if (angle > Mathf.Epsilon)
                    {
                        if (thisTarget.transform.position - transform.position != Vector3.zero)
                        {
                            DIY_Movement.SoftLookAt(this.gameObject, thisTarget.transform.position, 30);
                        }
                    }
                    else
                    {
                        transform.Translate(Vector3.forward * speed * Time.deltaTime);
                    }
                }



                if (Vector3.Distance(transform.position, thisTarget.transform.position) < 0.5f)
                {//到达路径点后执行
                    if (wpsIndex < target.GetComponent <Dock>().wps.Length - 1)
                    {
                        wpsIndex++;
                    }
                    else
                    {
                        transform.position = thisTarget.transform.position;
                        if (target.tag == "Part")
                        {
                            TestPart part = target.GetComponentInChildren <TestPart>();
                            part.gameObject.transform.parent        = transform;
                            part.gameObject.transform.localRotation = Quaternion.Euler(Vector3.zero);
                            part.gameObject.transform.localPosition = Vector3.zero;
                            Destroy(target);
                            docking    = false;
                            target     = null;
                            wpsIndex   = 0;
                            thisTarget = null;
                            if (part.tag == "Laser")
                            {
                                this.GetComponent <Fire>().lasterGun = true;
                            }
                        }
                        else
                        {
                            transform.parent = target.transform;
                            if (target.GetComponent <DockGuide>() != null)
                            {
                                target.GetComponent <DockGuide>().docking = true;
                            }
                            if (target.gameObject.name == "Portal")
                            {
                                transform.parent = GameObject.Find("KeepPlayer").transform;
                                target           = null;
                                wpsIndex         = 0;
                                docking          = false;
                            }
                        }
                        //docking = false;
                        //target = null;
                        //Debug.Log ("docked");
                    }
                }
            }
            else
            {
                docking = false;
                Debug.Log("范围内无目标");
            }
        }
    }
 void RunAway()
 {
     DIY_Movement.SoftLookAt(this.gameObject, transform.position + (transform.position - enemy.position), 60f);
     speed = maxSpeed;
 }