unity做小游戏一般会用到的一些函数
2013-09-05 17:42
260 查看
物理材质 physic material
在Assets->Create->physic material可以修改摩擦力和弹力
物体碰撞时,两个物体都需要添加碰撞(Colloder),只有这样物体碰撞时才不会穿透过去。
mesh Renderer
看碰撞体
untiy 使用多线程函数
StartCoroutine(DestryPreviousBall(Basketball,3.0f));
IEnumerator DestryPreviousBall(Rigidbody ball,float time)
{
yield return new WaitForSeconds(time);
Destroy(ball.gameObject);
}
//旋转函数
gameObject.transform.RotateAround(
new Vector3(-0.01934576f,-1.633793f,-3.37289f),
new Vector3(0,1,0),
speed);
播放动画
gameObject.animation.PlayQueued("idle");
复制物体
public Rigidbody TempBasketBall;
public Transform hand;
Rigidbody Basketball;
Basketball = Instantiate(TempBasketBall,hand.position,hand.rotation) as Rigidbody;
Basketball.renderer.enabled = true;
Basketball.transform.parent = hand;
物体运动
Basketball.rigidbody.velocity = new Vector3(speedx,4.0f,speedz);
碰撞反弹碰撞
void OnCollisionEnter(Collision collisionInfo)
{
Debug.Log("碰撞"+gameObject.name);
if(collisionInfo.collider.gameObject.name.Contains(gameObject.name))
{
GameObject.Destroy(gameObject,3.0f);
}
}
碰撞不反弹
public AudioClip hitSound;
void OnCollisionEnter(Collision collision)
{
播放声音,在某个位置
AudioSource.PlayClipAtPoint(hitSound,new Vector3(1,0,0));
}
设置界面
ONGUI
if(myskin)
GUI.skin = myskin;
GUI.skin.label.normal.textColor = Color.white;
GUI.Label(new Rect(10,30,60,30),"分数:");
//按钮
bool btnstat = GUI.Button(new Rect(Screen.width/2-50,Screen.height/2+30,100,50),"结束");
退出函数
Application.Quit();
调整旋转角度
goba.transform.rotation = Quaternion.Euler(0,0,0);
调整位置
goba.transform.position = new Vector3(-0.07937647f,-1.74901f,-2.658201f);
string转float型
float a = float.Parse(Mathf.Atan(z/x).ToString("#0.00"));
在Assets->Create->physic material可以修改摩擦力和弹力
物体碰撞时,两个物体都需要添加碰撞(Colloder),只有这样物体碰撞时才不会穿透过去。
mesh Renderer
看碰撞体
untiy 使用多线程函数
StartCoroutine(DestryPreviousBall(Basketball,3.0f));
IEnumerator DestryPreviousBall(Rigidbody ball,float time)
{
yield return new WaitForSeconds(time);
Destroy(ball.gameObject);
}
//旋转函数
gameObject.transform.RotateAround(
new Vector3(-0.01934576f,-1.633793f,-3.37289f),
new Vector3(0,1,0),
speed);
播放动画
gameObject.animation.PlayQueued("idle");
复制物体
public Rigidbody TempBasketBall;
public Transform hand;
Rigidbody Basketball;
Basketball = Instantiate(TempBasketBall,hand.position,hand.rotation) as Rigidbody;
Basketball.renderer.enabled = true;
Basketball.transform.parent = hand;
物体运动
Basketball.rigidbody.velocity = new Vector3(speedx,4.0f,speedz);
碰撞反弹碰撞
void OnCollisionEnter(Collision collisionInfo)
{
Debug.Log("碰撞"+gameObject.name);
if(collisionInfo.collider.gameObject.name.Contains(gameObject.name))
{
GameObject.Destroy(gameObject,3.0f);
}
}
碰撞不反弹
public AudioClip hitSound;
void OnCollisionEnter(Collision collision)
{
播放声音,在某个位置
AudioSource.PlayClipAtPoint(hitSound,new Vector3(1,0,0));
}
设置界面
ONGUI
if(myskin)
GUI.skin = myskin;
GUI.skin.label.normal.textColor = Color.white;
GUI.Label(new Rect(10,30,60,30),"分数:");
//按钮
bool btnstat = GUI.Button(new Rect(Screen.width/2-50,Screen.height/2+30,100,50),"结束");
退出函数
Application.Quit();
调整旋转角度
goba.transform.rotation = Quaternion.Euler(0,0,0);
调整位置
goba.transform.position = new Vector3(-0.07937647f,-1.74901f,-2.658201f);
string转float型
float a = float.Parse(Mathf.Atan(z/x).ToString("#0.00"));
相关文章推荐
- [转贴]一些经常会用到的Javascript检测函数
- 一些经常会用到的Javascript检测函数
- 一些经常会用到的Javascript检测函数
- 一些经常会用到的vbscript检测函数
- ios开发之--开发中可能会用到的一些函数
- unity Unet中标签函数用法 以及一些功能的实现思路(全是干货)
- Oracle经常用到的一些函数
- dm9000驱动中用到一些函数的解释
- Matlab中机器学习会用到的一些特殊函数
- 经常用到的一些函数
- 一些用到过的C 函数
- Oracle经常用到的一些函数
- 一些经常会用到的Javascript检测函数
- 调用一些表单验证函数主要用到blur()
- matlab2012一些函数删除后的替代解决方法及用到操作
- php data()函数中用到的一些常量
- php一些平时没 用到的函数
- 最近用到的一些封装函数~
- VS2010画图用到的一些函数
- PHP的魔术方法/魔术变量以及php用到的一些函数