小球吃金币unity教程_Unity里吃金币效果的实现

利用球形检测Physics.OverLapSphere实现吃金币效果玩家身上的脚本using UnityEngine;using System.Collections;public class CubeMove : MonoBehaviour {//此脚本应挂载在玩家身上//设置一个bool值bool isMagnet = false;public float speed;// Use this ...
摘要由CSDN通过智能技术生成

利用球形检测Physics.OverLapSphere实现吃金币效果

玩家身上的脚本

using UnityEngine;

using System.Collections;

public class CubeMove : MonoBehaviour {

//此脚本应挂载在玩家身上

//设置一个bool值

bool isMagnet = false;

public float speed;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

//游戏对象向前移动的逻辑

transform.Translate(transform.forward *speed * Time.deltaTime);

//判断条件//碰撞器触发变为true

if (isMagnet)

{

//利用球形检测(球心坐标,半径)

//返回值类型为碰撞器Collider类型

Collider[] cols = Physics.OverlapSphere(transform.position, 10);

foreach (var item in cols)

{

//找到标签为Coin的对象

if (item.gameObject.CompareTag("Coin"))

{

//注:获取当前对象的CoinMove自定义组件中的公共变量设为true

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值