2020-10-04

本文详细介绍了如何使用Unity 3D制作一个吃金币游戏,包括设置场景、实现金币旋转、小球的重力运动、碰撞检测、相机跟随、UI界面展示得分及暂停/开始功能的实现。
摘要由CSDN通过智能技术生成

**

用Unity 3D做简单的吃金币游戏步骤如下

**

1、做出大致场景
在这里插入图片描述
2、金币旋转
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class xuanzhuan : MonoBehaviour
{
public float xz;
// Start is called before the first frame update
void Start()
{
xz = 120.0f; //旋转速度即角速度
}

// Update is called once per frame
void Update()
{
    transform.Rotate(new Vector3(0, 1, 0) * xz * Time.deltaTime); //绕Y轴旋转
}

}
3、小球运动利用重力系统
1、先添加重力系统在属性栏的 Add Componet 添加
在这里插入图片描述
2、代码实现小球运动和碰到金币消失
下面展示一些 内联代码片

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class frist : MonoBehaviour
{

public Rigidbody rg;  
public float sudu;
// Start is called before the first frame update
void Start()
{
    sudu = 20.0f;   //小球速度
    rg = GetComponent<Rigidbody>(); 
}

// Update is called once per frame
void Update()
{
    //  运动和键盘绑定前后左右跳(W,S,A,D,Speca)
    if (Input.GetKey(KeyCode.W))
    {
        rg.AddForce(Vector3.forward * Time.deltaTime * sudu);
        //transform.Translate(Vector3.forward * Time.deltaTime * sudu);
    }
    if (Input.GetKey(KeyCode.A))
    {
        rg.AddForce(Vector3.left * Time.deltaTime * sudu);
        //transform.Translate(Vector3.left * Time.deltaTime * sudu);
    }
    if (Input.GetKey(KeyCode.S))
    {
         rg.AddForce(Vector3.back * Time.deltaTime * sudu);
        //transform.Translate(Vector3.back * Time.deltaTime * sudu);
    }
    if (Input.GetKey(KeyCode.D))
    {
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值