相关文章推荐
冷冷的萝卜  ·  Spring - ...·  2 年前    · 

I have tried a few things, including this…NOT working for me.
Maybe I need help with the Inspector details.
Can somebody check this??

using UnityEngine;
using System.Collections;
public class Jump : MonoBehaviour {
    CharacterMotor playerScript;
    // Use this for initialization
    void Start () {
       playerScript = (CharacterMotor)GameObject.FindGameObjectWithTag("Player").GetComponent("CharacterMotor");
    // Update is called once per frame
    void Update () {
    void OnTriggerEnter(Collider other) {
        if (other.gameObject.tag == "Player"){
         Debug.Log("Enter!"); //work fine        
         playerScript.jumping.baseHeight=10;
    void OnTriggerExit(Collider other) {
        if (other.gameObject.tag == "Player"){
         Debug.Log("Exit!"); //work fine
         playerScript.jumping.baseHeight=1;
    void OnTriggerStay(Collider other) {
        if (other.gameObject.tag == "Player"){
         Debug.Log("Stay!"); //work fine
    if (col.tag == "Player"){
       dir = (col.transform.position - transform.position).normalized;
       var charMotor = col.GetComponent(CharacterMotor);
       charMotor.SetVelocity(dir*velBack);

Make a collider for your jump object and Do Not Check “Is Trigger”. This will be your normal Collider to keep your player from going through your object.

Make another Collider larger than your object that you want the player to run into or jump on to make the action take place. Check the “Is Trigger” box

Add another Capsule Collider to your Player just a little larger than player. Do Not check the “Is Trigger” box.

Place this C# or JS code line on your Player by adding to another code already assigned to your Player.

void OnExternalVelocity(){
function OnExternalVelocity(){

( This keeps an annoying warning from appearing because of the charMotor item on Line 8.)

In your Inspector on the jump object, set the velBack number to what you desire to be the jumping level. This script can be attached to many other jumping platforms and YOU control the jumping height in the Inspector section.
Note that, if the player continuously jumps on the same spot on the pad and hits the “jump” key, it is possible to go higher. This works great and the Capsule shape collider you added to player makes for some great effects if the player catches the edge of the platform. Player bounces back off that edge. Very useful if you want to jump across a gorge or something.