Guest User

Jumper

a guest
Sep 18th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Jumper : MonoBehaviour {
  6.     private bool isJumping = false;
  7.     private Rigidbody rb;
  8.     public Vector3 jumplength = new Vector3(0, 100, 0);
  9.     // Use this for initialization
  10.     void Start () {
  11.        
  12.     }
  13.    
  14.     // Update is called once per frame
  15.     void Update () {
  16.         if(isJumping == true)
  17.         {
  18.             rb.AddForce(Vector3.up + jumplength);
  19.             isJumping = false;
  20.         }
  21.     }
  22.     private void OnTriggerEnter(Collider other)
  23.     {
  24.         if(other.gameObject.tag == "Player")
  25.         {
  26.             rb = other.gameObject.GetComponent<Rigidbody>();
  27.             isJumping = true;
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment