Last active
February 14, 2020 21:14
-
-
Save WakkyFree/7e4fcf8d195d8e5c6c48ec748dc8b34d to your computer and use it in GitHub Desktop.
Unity script to shoot a ball
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class ShootBall : MonoBehaviour { | |
private float timer = 0.0f; | |
private float timeLimit = 1.0f; | |
public static bool shootSwitch; | |
// Use this for initialization | |
void Start () { | |
shootSwitch = true; | |
} | |
// Update is called once per frame | |
void Update () { | |
if(shootSwitch) { | |
timer += Time.deltaTime; | |
} | |
if((timer > timeLimit) & shootSwitch) { | |
float z = 2000; // force strength; | |
Rigidbody rigidbody = GetComponent<Rigidbody>(); | |
rigidbody.AddForce(0, 0, -z); | |
timer = 0.0f; | |
shootSwitch = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its asking for shoot switch but I cant find that on his acc