Dynamic bouncing ball project
followComplexNamingBouncingAdvancedTimer.js
var i = 0;
function Start() {
for (i=0; i<1; i++)
var spherea = GameObject.CreatePrimitive(PrimitiveType.Sphere);
spherea.name = "Large Sphere";
spherea.transform.localScale = Vector3(1.6,1.6,1.6);
spherea.transform.position = Vector3 (109, 159, 101);
spherea.AddComponent(Rigidbody);
spherea.collider.material = new PhysicMaterial("bouncy2");
spherea.collider.material.dynamicFriction = .3f;
spherea.collider.material.frictionCombine = PhysicMaterialCombine.Average;
spherea.collider.material.bounciness = .6f;
spherea.collider.material.bounceCombine = PhysicMaterialCombine.Average;
var sf : SmoothFollow = Camera.main.GetComponent(SmoothFollow);
if (!target)
target = spherea.transform;
}
var target : Transform;
function Update () {
transform.LookAt(target);
}
private var startTime : int;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var countDownSeconds : int;
function Awake() {
startTime = Time.time;
}
function OnGUI () {
//make sure that your time is based on when this script was first called
//instead of when your game started
var guiTime = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);
//do stuff based on your timer
if (restSeconds == -10) {
Awake();
Start();
}
//display the timer
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Label (Rect (400, 25, 100, 30), text);
}
Move by frame rate code:
function Update () {
transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
}
Move by time code:
var speed = 5.0;
function Update () {
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, 0, z);
}
Look at target code:
var target : Transform;
function Update () {
transform.LookAt(target);
}
Switch code:
var switchToTarget : Transform;
function Update () {
if (Input.GetButtonDown("Jump"))
GetComponent(follow).target = switchToTarget;
}
Collide & Destroy code:
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == "bottomCollider"){
Destroy(collision.gameObject);
}
}