简体   繁体   English

Unity AddForce 到播放器 onTriggerEnter

[英]Unity AddForce to Player onTriggerEnter

Screenshot Game "I'm making a game, i want to create a bounce script when the player jumps on a box and bounces up, this is what i have so far"截图游戏“我正在制作一个游戏,我想在玩家跳上一个盒子并弹起时创建一个弹跳脚本,这就是我目前所拥有的”

public Rigidbody rb;
public float bounceForce = 3f;

// Start is called before the first frame update
void Start()
{
    rb = GetComponent<Rigidbody>();
    
}

void OnTriggerEnter(Collider coll) {
    if(coll.gameObject.tag == "Player"){
        Debug.Log("Jumpforce");
        GetComponent<Rigidbody>().AddForce (0,bounceForce,0);
        
    }
    
}

i got it我知道了

void OnTriggerEnter(Collider other) {
    if(other.gameObject.tag == "Player"){
        Debug.Log("JumpForce Added");
        other.gameObject.GetComponent<Rigidbody>().AddForce(Vector3.up*bounceForce, ForceMode.Impulse);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM