Unity-实现“保龄球”运动

点击空格即发送保龄球

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BLQ : MonoBehaviour
{
    float jiafen = 0;//没实现
    GameObject blq;//获取保龄球
    Rigidbody bll;//给保龄球获取的力声明
    public float blqap = 10f;//保龄球速度

    // Start is called before the first frame update
    void Start()
    {
        blq = GameObject.Find("ball");
        bll = blq.GetComponent<Rigidbody>();//游戏开始获取保龄球的力
        jiafen = 0;//没实现
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))//按下空格键保龄球向前冲
        {
            bll.AddForce(new Vector3(0, 0, 1) * blqap * Time.deltaTime, ForceMode.Impulse);//保龄球冲的方向(向 Rigidbody 添加力。沿 force 矢量的方向连续施加力。)
            bll.AddTorque(new Vector3(0, 1, 0) * blqap * Time.deltaTime, ForceMode.Impulse);//向Y轴给保龄球添加扭矩力(向刚体添加扭矩。力只能应用于处于活动状态的刚体。如果 GameObject 处于非活动状态,则 AddTorque 没有效果。默认将唤醒刚体。如果扭矩大小为零,则不会唤醒刚体。)
        }

    }
    private void OnTriggerEnter(Collider other)//加分meishix
    {
        jiafen += 1;
        Debug.Log("撞到瓶子,开始加分当前分数:" + jiafen);

    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值