Unity3D物体在UI界面的显示同时控制模型旋转

Posted clhxxlcj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3D物体在UI界面的显示同时控制模型旋转相关的知识,希望对你有一定的参考价值。

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

public class ChinarSmoothUi3DCamera : MonoBehaviour 

    public Transform point;
    private Vector3 Tras = Vector3.zero;

    public float distance = 10.0f;
    public float minDistance = 2f;
    public float maxDistance = 15f;
    public float zoomSpeed = 1f;
    public float xSpeed = 250.0f;
    public float ySpeed = 250.0f;
    public bool allowYTilt = true;
    public float yMinLimit = -90f;
    public float yMaxLimit = 90f;

    private float x = 0.0f;
    private float y = 0.0f;
    private float targetX = 0f;
    private float targetY = 0f;
    public float targetDistance = 0f;
    private float xVelocity = 1f;
    private float yVelocity = 1f;
    private float zoomVelocity = 1f; 
    public static ChinarSmoothUi3DCamera Instance;   
    private void Awake()
    
        Instance = this;
    
    void Start ()         
        Vector3 tange = transform.eulerAngles;
        targetX = x = tange.x;
        targetY = y = ClampAngle(tange.y, yMinLimit, yMaxLimit);       
        targetDistance = distance;

    

    // Update is called once per frame   
    void LateUpdate() 

        Sencoend();
        //First();
    
    void Sencoend()
    
         if (point == null)
         
            return;
         
         if (Input.GetMouseButton(1))
         
            targetX += Input.GetAxis("Mouse X")*-1 * xSpeed * 0.02f;
         
        x = Mathf.SmoothDampAngle(x, targetX, ref xVelocity, 0.3f);
        Quaternion rotation = Quaternion.Euler(0, x, 0);
        point.transform.rotation = rotation;
       
    



    void First()
    

    if (point==null)
        
            return;
        
        if(Input.GetAxis("Mouse ScrollWheel")>0)
        
            targetDistance -= zoomSpeed;
        
        if(Input.GetAxis("Mouse ScrollWheel")<0)
        
            
            targetDistance += zoomSpeed;
        
        targetDistance = Mathf.Clamp(targetDistance, minDistance, maxDistance);
        if(Input.GetMouseButton(1))
        
            
            targetX+= Input.GetAxis("Mouse X") * xSpeed * 0.02f;           
            if (allowYTilt)
            
                targetY -= Input.GetAxis("Mouse Y") * xSpeed * 0.02f;
                targetY= ClampAngle(targetY, yMinLimit, yMaxLimit);
            
         
       x = Mathf.SmoothDampAngle(x, targetX, ref xVelocity, 0.3f);
        y = allowYTilt ? Mathf.SmoothDampAngle(y, targetY, ref yVelocity, 0.3f) : targetY;
        Quaternion rotation = Quaternion.Euler(y, x, 0);
        distance = Mathf.SmoothDamp(distance, targetDistance, ref zoomVelocity, 0.5f);
        Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + point.position + Tras;
        transform.rotation = rotation;
        transform.position = position;
       
    


    public float ClampAngle(float angle,float min,float max)
    
        if(angle>360)
        
            angle -= 360;
        
        if(angle<-360)
        
            angle += 360;
        
        return Mathf.Clamp(angle, min, max);
    

  

以上是关于Unity3D物体在UI界面的显示同时控制模型旋转的主要内容,如果未能解决你的问题,请参考以下文章

在unity3d里怎样隐藏物体?

Unity3D 在运行时实现物体的移动旋转伸缩控制

Unity3D 控制物体移动旋转缩放

unity3d物体旋转

Unity3D日常开发Unity3D拓展开发:UI界面控制,UI界面的显示和隐藏实现

Unity3d--角色与UI混合显示--实现角色旋转触控