unity 3d 按键触发命令 和 c# 小数点位数修改

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


public class Test : MonoBehaviour 
{
    public GameObject Tracker;
    private Vector3 t1;
    private Vector3 t2;
    private float Distance;

	// Use this for initialization
	void Start () 
    {
        t1 = Vector3.zero;
        t2 = Vector3.zero;
        Distance = 0f;
        
	}
	
	// Update is called once per frame
	void Update () 

    {
        
        if (Input.GetKeyDown(KeyCode.Q))
        {
            t1 = Tracker.transform.position;

           
            t1.x = (float)(Mathf.Round(t1.x * 1000) / 1000);
            t1.y = (float)(Mathf.Round(t1.y * 1000) / 1000);
            t1.z = (float)(Mathf.Round(t1.z * 1000) / 1000);

            print("t1 is " + "(" + t1.x + "," + t1.y + "," + t1.z+")");
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            t2 = Tracker.transform.position;
            t2.x = (float)(Mathf.Round(t2.x * 1000) / 1000);
            t2.y = (float)(Mathf.Round(t2.y * 1000) / 1000);
            t2.z = (float)(Mathf.Round(t2.z * 1000) / 1000);
            print("t2 is " + "(" + t2.x + "," + t2.y + "," + t2.z + ")");
           // print("t2 is " + t2);

        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Distance = Mathf.Sqrt((t1 - t2).sqrMagnitude);
            //t1 = t2;
            Distance *= 100;
            print("Distance is" + Distance);
           
        }

       
	}
}

1, unity3d输入与控制——键盘事件

2, unity一些键盘鼠标特殊触发事件总结

你可能感兴趣的:(C#,unity/blender)