20141022unity学习笔记

虽然我写的东西很不入流,老师沉痛的打击了我说我写的东西就是代码罗列,但是我喜欢写这个,不管别人说什么,这会是大学毕业的时候我对我大三大四的一种美好的回忆~~

前几天看见群里发的题,我深深被虐惨了,初学unity,看API还是太少,所以做不出来自己想要的结果很正常,但是只要继续,就不会太差。

叭叭Shpere朝向Cube运动吧,这是入门基础了吧,这里面运用了一个函数Vector3.moveTowards。

函数很简单,只要定义一个起始位置和获取目标的位置就好。

public Vector3 targetPos;

public float speed=1.0f;

public bool Isrun;

void start()

{

targetPos=GameObject.Find("Cube").GetComponent<Transform>().position;

}

void Update()

{

if(Isrun)

transform.position=Vector3.moveTowards(transform.position,tangetPos,Time.deltaTime*speed);

}

进而我们来写地震或者瑟瑟发抖时Cube的抖动问题,说白了就是对上面函数的延伸,不过这次尝试用不同的函数去写,用Vector3.Lerp;

public float treSpeed = 0.0f;
public Vector3 startPosition;
public bool isTre = true;
void Start()
{
startPosition = transform.position;
}
void Update()
{
if (isTre)
{
transform.position = Vector3.Lerp(startPosition, transform.position, Time.deltaTime);
if (startPosition == transform.position)
isTre = false;
}
else
{
transform.position = startPosition + new Vector3(Random.value * treSpeed, Random.value * treSpeed, Random.value * treSpeed);
isTre = true;
}

逻辑性太差我感觉要把一些数据结构什么的,进行深刻的学习了

posted on 2014-10-22 15:17  哇啦啦啦  阅读(189)  评论(0编辑  收藏  举报

导航