C# Loop script,C# LOOP SCRIPT HELP NEEDED!
Im new to unity so im pretty noob in scripting. I was wondering could someone write down a script so my other script can repeat itself (if that makes sense).
WHY do I need a script to repeat itself? Because i tried to make my ball (player) bounce so it always bounces to reach the same height (i know about that trick where u put bounciness to 0.980524) but when i drop down from somewhere (lets say Y=0 to Y=-5 ) I would gain so much momentum that i could get back to where i jumped from (Y=0)
So i was thinking maybe i can put a jump script to keep repeating itself so it would look like I am bouncing.
The jump script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(Rigidbody))] public class Jump : MonoBehaviour {
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
void Update(){
if(Input.GetKeyDown(KeyCode.Space) && isGrounded){
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
,