经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » 游戏设计 » 查看文章
球球大作战 01 小球的移动和碰到金币,金币会消失。
来源:cnblogs  作者:优梦创客  时间:2019/8/26 8:28:46  对本文有异议

版权申明:

  • 本文原创首发于以下网站:
  1. 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123
  2. 优梦创客的官方博客:https://91make.top
  3. 优梦创客的游戏讲堂:https://91make.ke.qq.com
  4. 『优梦创客』的微信公众号:umaketop
  • 您可以自由转载,但必须加入完整的版权声明!

球球大作战小球的移动和碰到金币,金币会消失。


吃到金币

  1. public class SphereMove : MonoBehaviour
  2. {
  3. public float Spheremove = 20;
  4. public float Spherejump = 50;
  5. // Start is called before the first frame update
  6. void Start()
  7. {
  8. }
  9. // Update is called once per frame
  10. void Update()
  11. {
  12. if (Input.GetKey(KeyCode.UpArrow))
  13. {
  14. GetComponent<Rigidbody>().AddForce(Spheremove, 0, 0);
  15. }
  16. if (Input.GetKey(KeyCode.DownArrow))
  17. {
  18. GetComponent<Rigidbody>().AddForce(-Spheremove, 0, 0);
  19. }
  20. if (Input.GetKey(KeyCode.LeftArrow))
  21. {
  22. GetComponent<Rigidbody>().AddForce(0, 0, Spheremove);
  23. }
  24. if (Input.GetKey(KeyCode.RightArrow))
  25. {
  26. GetComponent<Rigidbody>().AddForce(0, 0, -Spheremove);
  27. }
  28. if (Input.GetKey(KeyCode.Space))
  29. {
  30. GetComponent<Rigidbody>().AddForce(0, Spherejump, 0);
  31. }
  32. }
  33. public void OnTriggerEnter(Collider other)
  34. {
  35. if (other.gameObject.tag == ("Goodup"))
  36. {
  37. other.gameObject.SetActive(false);
  38. }
  39. }
  40. }

金币围绕Y轴转动金币围绕Y轴转动。

  1. public class Pickupsctrl : MonoBehaviour
  2. {
  3. public Vector3 rot;
  4. // Start is called before the first frame update
  5. void Start()
  6. {
  7. }
  8. // Update is called once per frame
  9. void Update()
  10. {
  11. rot = new Vector3(0, 20, 0);
  12. rot = rot* Time.deltaTime;
  13. transform.Rotate(rot);
  14. }
  15. }

相机跟随小球移动相机跟随小球移动。

  1. public class Canearctrl : MonoBehaviour
  2. {
  3. public Vector3 Offset;
  4. public Transform player;
  5. // Start is called before the first frame update
  6. void Start()
  7. {
  8. Offset = this.transform.position - player.position;
  9. }
  10. // Update is called once per frame
  11. void Update()
  12. {
  13. this.transform.position = player.position + Offset;
  14. }
  15. }

原文链接:http://www.cnblogs.com/raymondking123/p/11404018.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号