Skip to content

Instantly share code, notes, and snippets.

@yjsoon
Last active April 7, 2017 09:31
Show Gist options
  • Save yjsoon/d5d068bbe55b0843bad2006a12e4e9a4 to your computer and use it in GitHub Desktop.
Save yjsoon/d5d068bbe55b0843bad2006a12e4e9a4 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallGeneratorScript : MonoBehaviour {
public Rigidbody ballTemplate;
public float ballSpeedX = 200.0f;
public float ballSpeedY = -100.0f;
public float startTime = 0.0f;
public float timeInterval = 5.0f;
// Use this for initialization
void Start () {
InvokeRepeating ("GenerateBall", startTime, timeInterval);
}
// Update is called once per frame
void Update () {
}
void GenerateBall() {
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
Rigidbody generatedBall = (Rigidbody)Instantiate (ballTemplate, pos, rot);
generatedBall.AddForce (new Vector3 (ballSpeedX, ballSpeedY, 0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment