unity关于相机移动

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Move
{

public Camera cachedCam;
public Camera orthCam;
public InputField inputfield1;
public InputField inputfield2;
public Button btn;

public void Onmove(Camera cachedCam,float x,float y, float angle)
{

    Vector3 temp = new Vector3();
    temp = cachedCam.transform.position;
    Vector3 dir = new Vector3();
    dir.x = x;
    dir.y = 0;
    dir.z = y;
    cachedCam.transform.position = Vector3.Lerp(temp,dir,0.5f);
    Vector3 temprotation = cachedCam.transform.rotation.eulerAngles;
    temprotation.y = angle;
  

}
void Rotating(float hor, float ver)
{
    //获取方向
    Vector3 dir = new Vector3(hor, 0, ver);
    //将方向转换为四元数
    Quaternion quaDir = Quaternion.LookRotation(dir, Vector3.up);
    //缓慢转动到目标点
   // transform.rotation = Quaternion.Lerp(transform.rotation, quaDir, Time.deltaTime * 100f);
}
void OnCameraMove( Vector3 pos, Vector3 dir)
{
    if (cachedCam )
    {
        dir.y = 0;
      //  Vector3 oldDirXZ = transform.forward;
       // oldDirXZ.y = 0;
       // oldDirXZ.Normalize();
    //    Quaternion rot = Quaternion.FromToRotation(oldDirXZ, dir);

        //Vector3 newpos = new Vector3(pos.x, transform.position.y, pos.z);
        Vector3 newpos = new Vector3(pos.x, 0, pos.z);
        if (orthCam)
        {
            float w = 2 * orthCam.orthographicSize * 16.0f / 9.0f;
            float h = 2 * orthCam.orthographicSize;

            Vector3 org = orthCam.transform.position;
            Vector3 right = orthCam.transform.right;
            Vector3 up = -orthCam.transform.up;
            newpos = org + w * right * (newpos.x - 0.5f) + h * up * (newpos.z - 0.5f);
        }
       // Vector3 v = transform.rotation.eulerAngles;
      //  v.y += rot.eulerAngles.y;
      //  transform.rotation = Quaternion.Euler(v);
      //  transform.position = new Vector3(newpos.x, transform.position.y, newpos.z);
        //transform.rotation = rot * transform.rotation;
    }
}
Vector3 GetDir(string name)
{
    string temp;
    Vector3 dir = new Vector3();

    temp = name.Replace("(", "").Replace(")", "");

    string[] tmp = temp.Split(',');

    dir.x = float.Parse(tmp[0]);
    dir.y = 0;
    dir.z = float.Parse(tmp[1]);
    //(0,1)
    return dir;
}
public void Onclick()
{
    OnCameraMove(GetDir(inputfield1.text), GetDir(inputfield2.text));
}

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值