您的位置:首页 > 移动开发 > Unity3D

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"));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: