unity做小游戏一般会用到的一些函数

物理材质 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);

 

 

stringfloat

float a = float.Parse(Mathf.Atan(z/x).ToString("#0.00"));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值