- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
Unity 相机跟随 - <span style="font-family:SimSun;font-size:14px;">using UnityEngine;
- using System.Collections;
- public class look : MonoBehaviour {
- public Transform target;
- // Use this for initialization
- void Start () {
-
- }
-
- // Update is called once per frame
- void Update () {
-
- transform.LookAt (target.position);
- }
- }
- </span>
复制代码 Unity OnTrigger和List使用 - using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Ontriggle : MonoBehaviour {
- List<Color> colorlist;
- // Use this for initialization
- void Start () {
-
- }
-
- // Update is called once per frame
- void Update () {
-
- }
- void OnTriggerEnter(Collider other)
- {
- colorlist=new List<Color>();
- for(int i=0;i<other.renderer.materials.Length;i++)
- {
- colorlist.Add(other.renderer.materials[i].color);
- other.renderer.materials[i].color=Color.red;
- }
- }
- void OnTriggerStay(Collider other)
- {
- Debug.Log ("-------stay----");
- }
- void OnTriggerExit(Collider other)
- {
- for(int i=0;i<other.renderer.materials.Length;i++)
- {
- other.renderer.materials[i].color=colorlist[i];
- }
- }
- }
复制代码 Unity 控制物体移动和旋转 - <span style="font-size:18px;">using UnityEngine;
- using System.Collections;
- public class transform : MonoBehaviour {
- public float speed;
- public float rotspeed;
- // Use this for initialization
- void Start () {
-
- }
-
- // Update is called once per frame
- void Update () {
- if(Input.GetKey(KeyCode.W)){
- // transform.Translate(Vector3.*Time.deltaTime*speed);
- transform.Translate(Vector3.right*Time.deltaTime*speed);
- }
- else if(Input.GetKey(KeyCode.S)){
- transform.Translate(Vector3.left*Time.deltaTime*speed);
- }
- if(Input.GetKey(KeyCode.A)){
- transform.Rotate(Vector3.up*Time.deltaTime*(-rotspeed));
- }
- else if(Input.GetKey(KeyCode.D)){
- transform.Rotate(Vector3.up*Time.deltaTime*(rotspeed));
- }
- }
- }
- </span>
复制代码 |
|