PageRenderTime 55ms CodeModel.GetById 35ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/Scripts/Item.js

http://acid-and-base.googlecode.com/
JavaScript | 104 lines | 83 code | 11 blank | 10 comment | 32 complexity | 7b21b6a20efaecc86bba7bdf9f1bce06 MD5 | raw file
  1enum itemEnum { Pseudo=0, saltShaker=1 }
  2var itemType = itemEnum.Pseudo;
  3
  4private var pickedUp = false;
  5var pickedUpBy = -1;
  6// 0 = Red // 1 = Acid // 2 = Base
  7private var itemEnter = false;
  8private var holding = false;
  9
 10var showText = false;
 11var itemName = "";
 12var displayText = true;
 13
 14function Start ()
 15{
 16        if (collider == null)   
 17                gameObject.AddComponent(MeshCollider);
 18        collider.isTrigger = true;
 19} 
 20
 21function Update()
 22{
 23	// this will pick up the item.
 24	if (Input.GetKeyDown(KeyCode.E) && itemEnter && !pickedUp)
 25	{
 26		holding = gameObject.Find("Big Red").GetComponent(ItemInventory).holdingItem;
 27		pickedUpBy = gameObject.Find("Master Controller Light").GetComponent(MasterController_edit).activePlayer;
 28		if (pickedUpBy == 0 && !pickedUp && !holding)
 29		{
 30			// set up pickup condition as true.
 31			pickedUp = true;
 32			gameObject.Find("Big Red").GetComponent(ItemInventory).holdingItem = true;
 33		}
 34	}
 35
 36	else if (pickedUp)
 37	{
 38		// this will drop the item.
 39		if (Input.GetKeyDown(KeyCode.E))
 40		{
 41			pickedUp = false;
 42			gameObject.Find("Big Red").GetComponent(ItemInventory).holdingItem = false;
 43			//transform.position.y -= 1;				// TEMPORARY CODE
 44		}
 45	
 46		if (pickedUpBy == 0)
 47		{
 48			// if it is picked up, make the item float above Red
 49			transform.position = gameObject.Find("Big Red").GetComponent(Transform).position;
 50			transform.position.y += 1;		// item location (Y)
 51			//transform.position.z += 0.5;
 52		}
 53		else if (pickedUpBy == 1)
 54		{
 55			// nothing, acid cannot pick up items
 56		}
 57		else if (pickedUpBy == 2)
 58		{
 59			// nothing, base cannot pick up items
 60		}
 61	}
 62}
 63
 64function Reset ()
 65{
 66        if (collider == null)
 67                gameObject.AddComponent(MeshCollider);
 68        collider.isTrigger = true;
 69}
 70
 71// when something collides with this object...
 72function OnTriggerEnter(col : Collider)
 73{
 74	var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
 75	var properties : Properties = col.GetComponent(Properties);
 76	if(cmtr == null)
 77		return;
 78	showText = true;
 79	if(properties != null)
 80		return;
 81	itemEnter = true;
 82}
 83
 84function OnTriggerExit(col : Collider)
 85{
 86	var cmtr: CharacterMotor = col.GetComponent(CharacterMotor);
 87	var properties : Properties = col.GetComponent(Properties);
 88	if(cmtr == null)
 89		return;
 90	showText = false;
 91	if(properties != null)
 92		return;
 93	itemEnter = false;
 94}
 95
 96function OnGUI()
 97{
 98	if (showText && displayText)
 99	{
100		GUI.Box(Rect((Screen.width/2) - 100,50,200,40),""+itemName);
101	}
102}
103
104@script AddComponentMenu("Third Person Props/Item")