public void UseItem(scr_item a, scr_item b) { switch (a.myItemType) { case scr_item.itemType.EmptyBucket: if (b.myItemType == scr_item.itemType.Glue) { a.myItemType = scr_item.itemType.StickyBucket; b.SetDestroy(); } if (b.myItemType == scr_item.itemType.Toilet) { a.myItemType = scr_item.itemType.WaterBucket; } break; case scr_item.itemType.Glue: if (b.myItemType == scr_item.itemType.EmptyBucket) { a.myItemType = scr_item.itemType.StickyBucket; b.SetDestroy(); } if (b.myItemType == scr_item.itemType.Hair) { a.myItemType = scr_item.itemType.StickyHair; b.SetDestroy(); } break; case scr_item.itemType.Hair: if (b.myItemType == scr_item.itemType.Glue) { a.myItemType = scr_item.itemType.StickyHair; b.SetDestroy(); } if (b.myItemType == scr_item.itemType.EmptyBucket) { a.myItemType = scr_item.itemType.FuryBucket; b.SetDestroy(); } break; default: Debug.Log("CANNOT COMBINE"); break; } }
public void UseItem(scr_item a, scr_item b) { switch (a.myItemType) { case scr_item.itemType.EmptyBucket: if(b.myItemType == scr_item.itemType.Glue) { a.myItemType = scr_item.itemType.StickyBucket; b.SetDestroy(); } if(b.myItemType == scr_item.itemType.Toilet) { a.myItemType = scr_item.itemType.WaterBucket; } break; case scr_item.itemType.Glue: if(b.myItemType == scr_item.itemType.EmptyBucket) { a.myItemType = scr_item.itemType.StickyBucket; b.SetDestroy(); } if(b.myItemType == scr_item.itemType.Hair) { a.myItemType = scr_item.itemType.StickyHair; b.SetDestroy(); } break; case scr_item.itemType.Hair: if(b.myItemType == scr_item.itemType.Glue) { a.myItemType = scr_item.itemType.StickyHair; b.SetDestroy(); } if(b.myItemType == scr_item.itemType.EmptyBucket) { a.myItemType = scr_item.itemType.FuryBucket; b.SetDestroy(); } break; default: Debug.Log ("CANNOT COMBINE"); break; } }
// Update is called once per frame void Update() { if (MoveTrigger) { SetDirection(); } if (Input.GetMouseButtonDown(0)) { Ray rayLeft = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hitsLeft; hitsLeft = Physics.RaycastAll(rayLeft, 300f); if (hitsLeft.Length > 0) { foreach (RaycastHit hit in hitsLeft) { float hitDistance = Vector3.Distance(hit.point, this.transform.position); if (hitDistance > distanceInteraction) { StartMoving(hit); } } } PreviousPosition = this.transform.position; } if (Input.GetMouseButtonDown(1)) { Ray rayRight = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hitsRight; hitsRight = Physics.RaycastAll(rayRight, 300f); if (triggerRightClick && hitsRight.Length > 0) { foreach (RaycastHit hit in hitsRight) { if (triggerRightClick) { string hitTag = hit.transform.tag; float hitDistance = Vector3.Distance(hit.point, this.transform.position); switch (hitTag) { case "NPC": if (hitDistance < distanceInteractionNPC) { if (holdItem) { Debug.Log("I can use item on this NPC"); //manager.UseItem(); } triggerRightClick = false; } triggerRightClick = false; break; case "Item": if (hitDistance < distanceInteraction) { if (!holdItem && grabbedItem == null) { holdItem = true; grabbedItem = hit.transform.GetComponentInChildren <scr_item>(); grabbedItem.ItemGrabbed(this.transform); } else { scr_item targetItem = hit.transform.GetComponent <scr_item>(); manager.UseItem(grabbedItem, targetItem); } triggerRightClick = false; } break; case "Ground": if (grabbedItem && hitDistance < distanceToDrop) { grabbedItem.ItemDropped(hit.point); grabbedItem = null; holdItem = false; } triggerRightClick = false; break; default: break; } } } triggerRightClick = true; } } MyAnimator.SetFloat("speed", Agent.velocity.magnitude); }
// Update is called once per frame void Update() { if(MoveTrigger) SetDirection(); if(Input.GetMouseButtonDown(0)) { Ray rayLeft = Camera.main.ScreenPointToRay (Input.mousePosition); RaycastHit[] hitsLeft; hitsLeft = Physics.RaycastAll(rayLeft, 300f); if(hitsLeft.Length > 0) { foreach(RaycastHit hit in hitsLeft) { float hitDistance = Vector3.Distance(hit.point, this.transform.position); if(hitDistance > distanceInteraction) { StartMoving(hit); } } } PreviousPosition = this.transform.position; } if(Input.GetMouseButtonDown(1)) { Ray rayRight = Camera.main.ScreenPointToRay (Input.mousePosition); RaycastHit[] hitsRight; hitsRight = Physics.RaycastAll(rayRight, 300f); if(triggerRightClick && hitsRight.Length > 0) { foreach(RaycastHit hit in hitsRight) { if(triggerRightClick) { string hitTag = hit.transform.tag; float hitDistance = Vector3.Distance(hit.point, this.transform.position); switch(hitTag) { case "NPC": if(hitDistance < distanceInteractionNPC) { if(holdItem) { Debug.Log ("I can use item on this NPC"); //manager.UseItem(); } triggerRightClick = false; } triggerRightClick = false; break; case "Item": if(hitDistance < distanceInteraction) { if(!holdItem && grabbedItem == null) { holdItem = true; grabbedItem = hit.transform.GetComponentInChildren<scr_item>(); grabbedItem.ItemGrabbed(this.transform); } else { scr_item targetItem = hit.transform.GetComponent<scr_item>(); manager.UseItem(grabbedItem, targetItem); } triggerRightClick = false; } break; case "Ground": if(grabbedItem && hitDistance < distanceToDrop) { grabbedItem.ItemDropped(hit.point); grabbedItem = null; holdItem = false; } triggerRightClick = false; break; default: break; } } } triggerRightClick = true; } } MyAnimator.SetFloat ("speed", Agent.velocity.magnitude); }