Inheritance: MonoBehaviour
Example #1
0
    public void MouseToMove()
    {
        if (Input.GetKey(KeyCode.Mouse1) && MoveOrAttackSwitch)  //鼠标右键限定
        {
            //Debug.Log("MouseToMove()");
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;

            Physics.Raycast(ray, out hitInfo, 1 << LayerMask.NameToLayer("Terrain") | 1 << LayerMask.NameToLayer("Enemy"));
            //Debug.Log(hitInfo.point);
            if (hitInfo.collider.tag == "Terrain" &&
                Mathf.Abs(Vector3.Distance(GameObject.FindWithTag("Player").transform.position, hitInfo.point)) > 1)     //加限制
            {
                //Debug.Log("Terrain");
                Run.getInstance().RunToPos(hitInfo.point);              //坐标
                SmoothLookAt.getInstance().Init_Rotate(hitInfo.point);  //朝向

                NormalAttack.getInstance().attackTargetObj = null;
            }
            else if (hitInfo.collider.tag == "Enemy")
            {
                NormalAttack.getInstance().attackTargetObj = hitInfo.collider.GetComponentInParent <Enemy>().gameObject;
            }
            else
            {
                NormalAttack.getInstance().attackTargetObj = null;  //清空普攻目标
            }
        }
    }
Example #2
0
 void Start()
 {
     Cursor.visible = false;
     anim           = GetComponent <Animator>();
     smoothLook     = cam.GetComponent <SmoothLookAt>();
     folowPlayer    = cam.GetComponent <FolowPlayer>();
     CameraControll = cam.GetComponent <CameraControll>();
     playerMovement = GetComponent <PlayerMovement>();
     FindClosest    = GetComponent <FindClosest>();
 }
    // Use this for initialization

    void Start()
    {
        if (targetCamera == null)
        {
            Debug.LogWarning("Camera effect on GameObject " + gameObject.name + " is Missing a Camera, resorting to Main Camera!");
            targetCamera = Camera.main.GetComponent <SmoothLookAt>();
            if (targetCamera == null)
            {
                Debug.LogWarning("SmoothLookAt Navigator effect on GameObject " + gameObject.name + " is Missing a SmoothLookAt Camera, adding one to Main Camera!");
                targetCamera = Camera.main.gameObject.AddComponent(typeof(SmoothLookAt)) as SmoothLookAt;
            }
        }
    }
Example #4
0
 public void MoveAndAttackTargetObj()
 {
     if (attackTargetObj)
     {
         foreach (var item in EnemyTriggerList)
         {
             if (item == attackTargetObj)
             {
                 Run.getInstance().finishRun();
                 SmoothLookAt.getInstance().Init_Rotate(attackTargetObj.transform.position);  //朝向
                 doAttack();
                 return;
             }
         }
         Run.getInstance().RunToPos(attackTargetObj.transform.position);              //坐标
         SmoothLookAt.getInstance().Init_Rotate(attackTargetObj.transform.position);  //朝向
     }
 }
Example #5
0
 private void Awake()
 {
     instance = this;
     Init_Rotate(new Vector3(116, 0, 92));  //角色初始化朝向
 }