using UnityEngine;
using System.Collections;
public class BallDelay : MonoBehaviour {
public float jumpSpeed = 100;
public float timer;
Start ()
{
timer = 3;
}
Update ()
{
timer -= Time.deltaTime;
if (timer <= 0)
(
(GetComponent.AddForce(0, jumpSpeed, 0);
timer = 3;
)
}
}
Made in unity 5 I cant apply it to the gameobj says it has a compiler Error check it out maybe PLEASE???
Basically designed to have a ball delay of 3 seconds
Maybe…something like this of many options… (note: please try to use the code tags, makes is easy to read. )
using UnityEngine;
using System.Collections;
public class BallDelay : MonoBehaviour {
public float jumpSpeed = 500f;
public float timer = 5f;
private Rigidbody rb;
void Awake() {
// use here so, as to apply as object is activated
// IMPORTANT: make sure object has a Rigidbody Component attached (2D or 3D)
// NEVER use GetComponent() in Update() this calls it every second...only need
// to call ONCE...only put critcal functions / data in the Update() function
// as to keep your code fast....as possible. Hope it helps.. ;)
rb = GetComponent<Rigidbody>();
}
void Start ()
{
// Can use in void Awake() also
//rb = GetComponent<Rigidbody>();
//timer = 3;
}
void Update ()
{
timer -= Time.deltaTime;
if (timer <= 0f) {
rb.AddForce(0f, jumpSpeed, 0f);
timer = 5f;
}
//if (timer <= 0)
// (
//(GetComponent<Rigidbody>.AddForce(0, jumpSpeed, 0);
//timer = 3;
// )
}
}