创建平面和小球,给力或给速度让其弹起
给小球挂载刚体(Rigibdody)和脚本
(力是累计或者衰减的,直接给速度就是赋值,但如果+=速度就和力类似了)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class c4 : MonoBehaviour
{// 刚体组件private Rigidbody body;void Start(){// 加载刚体组件body = GetComponent<Rigidbody>();}// Update is called once per framevoid Update(){}// 开始碰撞private void OnCollisionEnter(Collision collision){// 给物体一个力// body.AddForce(Vector3.up * 300);// 给物体一个速度body.velocity = Vector3.up * 7;// 和给力的效果一样// body.velocity += Vector3.up * 7;}
}