[记录属性]unity 3D c#脚本语句集1

来源:互联网 发布:大数据应用在哪些行业 编辑:程序博客网 时间:2024/05/22 02:21
Input.GetButton ("Left")

输入名字为“Left”的Button,在edit->project settings->Input里面设置


Input.GetKey(KeyCode A)
输入键盘A键

using UnityEngine;using System.Collections;public class Mover : MonoBehaviour {public float h;public float v;public float l;public float s;public float turnSpeed = 50;public float moveSpeed = 10;void Start () {}void Update () {l = Input.GetAxis("Left");v = Input.GetAxis("Up");h=Input.GetAxis("Right");s=Input.GetAxis("Down");transform.Rotate (Vector3.up, h * turnSpeed * Time.deltaTime);transform.Rotate (Vector3.down, l * turnSpeed * Time.deltaTime);if (Mathf.Abs (v) > .5f) transform.Translate (Vector3.forward * v * moveSpeed * Time.deltaTime);if (Mathf.Abs (s) >.5f)transform.Translate(-Vector3.forward * s *moveSpeed*Time.deltaTime);}}

这段具体怎么实现的我也不知道,不过效果跟下面效果一样
if (Input.GetButton ("Left")) {//transform.Translate (new Vector3 (-1, 0, 0));transform.Rotate(Vector3.down);} else if (Input.GetButton ("Right")) {//transform.Translate (new Vector3 (1, 0, 0));transform.Rotate(Vector3.up);} else if (Input.GetButton ("Up")) {transform.Translate (new Vector3 (0, 0, Time.deltaTime));} else if (Input.GetButton ("Down")) {transform.Translate(new Vector3(0,0,-Time.deltaTime));}


transform.Rotate(Vector3.down)
旋转语句 点击打开链接


transform.Translate(new Vector3(0,0,-Time.deltaTime));
位置移动点击打开链接


transform.localScale = new Vector3 (Mathf.PingPong (Time.time, 2), Mathf.PingPong (Time.time, 2), Mathf.PingPong (Time.time, 2));
大小缩放。Mathf.PingPong点击打开链接

public float newIntensity;void Start () {newIntensity = light.intensity;}// Update is called once per framevoid Update () {ChangeIntensity ();}void ChangeIntensity(){float intensityA = .5f;float intensityB = 5f;if (Input.GetKeyDown (KeyCode.A)) {newIntensity = intensityA;}if (Input.GetKeyDown (KeyCode.D)) {newIntensity = intensityB;}light.intensity = Mathf.Lerp (light.intensity, newIntensity, Time.deltaTime);}

     渐变效果     Mathf.Lerp()   点击打开链接

void ChangePosition(){Vector3 postVect3A = new Vector3 (-5, 3, 0);Vector3 postVect3B = new Vector3 (5, 3, 0);if (Input.GetKeyDown(KeyCode.Q)) {newPosition = postVect3A;}if (Input.GetKeyDown(KeyCode.E)) {newPosition = postVect3B;}transform.position = Vector3.Lerp (transform.position, newPosition, Time.deltaTime);}

Vector3 的Lerp渐变






0 0
原创粉丝点击