Hey guys,I am new to javascript and c#.
I made a page collection script that works but there is one thing that I do not want it to happen,is that when all pages are collected,I want it to activate a gameobject,but it spawned the gameobject right at the start of the scene.
Script:
#pragma strict
@script RequireComponent ( AudioSource )
var document : int = 0;
var documentToWin = 5;
var distanceToPaper : float = 2.5;
public var paperPickup : AudioClip;
var Obj : GameObject;
function Start ()
{
Screen.lockCursor = true;
}
function Update ()
{
if(Input.GetMouseButtonDown (0) || Input.GetButtonDown ("Fire1"))
{
var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width * 0.5,
Screen.height * 0.5, 0.0));
var hit : RaycastHit;
if(Physics.Raycast(ray, hit, distanceToPaper))
{
if(hit.collider.gameObject.name == "document")
{
document += 1;
audio.PlayClipAtPoint(paperPickup, transform.position);
Destroy(hit.collider.gameObject);
}
}
}
}
if(document <= 5){
Obj.SetActive(true);
}
function OnGUI ()
{
if(document < documentToWin)
{
GUI.Box(Rect((Screen.width * 0.5) -60, 10, 120, 25), " " + document.ToString() + " / 5 collected");
}
else
GUI.Box(Rect((Screen.width/2) - 100, 10, 200, 35), "Get out of here within a minute!");
}
↧