点击空格即发送保龄球
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);
}
}