纳金网
标题:
相机跟随/OnTrigger和List使用/控制物体移动和旋转
[打印本页]
作者:
狂风大尉
时间:
2014-6-24 10:34
标题:
相机跟随/OnTrigger和List使用/控制物体移动和旋转
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>
复制代码
作者:
hyui
时间:
2014-6-24 17:53
THanks for sharing your experience!
作者:
HIDEOKOJIMA
时间:
2014-6-25 00:14
THanks for sharing
作者:
wucnj
时间:
2014-6-25 09:13
感谢分享!!!
作者:
shenyg77
时间:
2014-8-12 21:03
Thanks for sharing !
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5