您当前的位置: 首页 >  unity

鱼儿-1226

暂无认证

  • 0浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity3d 设置小球为刚体控制滚动

鱼儿-1226 发布时间:2020-08-17 18:30:38 ,浏览量:0

新建一个cube 作为地面。

新建一个Sphere

点击add component 选择刚体

新建脚本 Sphere 

 
  1. using System.Collections;

  2. using System.Collections.Generic;

  3. using UnityEngine;

  4.  
  5. public class Shpere : MonoBehaviour {

  6.  
  7. private Rigidbody rd;//刚体变量

  8. private int force = 5;//力量

  9. // Use this for initialization

  10. void Start () {

  11. rd = GetComponent();

  12. }

  13.  
  14. // Update is called once per frame

  15. void Update () {

  16. float h = Input.GetAxis("Horizontal");

  17. float v = Input.GetAxis("Vertical");

  18. rd.AddForce(new Vector3(h, 0, v)*5);

  19. }

  20.  
  21.  
  22. }

附加到sphere 上就可以控制小球运动了。根据方向键控制。

关注
打赏
1604459285
查看更多评论
立即登录/注册

微信扫码登录

0.5030s