コード例 #1
0
ファイル: CollidableObject.cs プロジェクト: fvivaudo/Rush01
		public void Start()
		{
			Collider c = GetComponent<Collider>();
			if (c == null)
			{	// must have collider to detect collisions
				if (!triggerWhenReachTarget)
				{
					Debug.LogError("CollidableObject must have a Collider.");
					enabled = false;
					return;
				}
			}
			else
			{
				if (GetComponent<Rigidbody>() == null) gameObject.AddComponent<Rigidbody>();
				GetComponent<Rigidbody>().useGravity = false;	// not using rigidbody for its physics in this way
				GetComponent<Rigidbody>().isKinematic = true;	// not using rigidbody for its physics in this way
				c.isTrigger = true;				// make sure it is trigger type collider since OnTriggerXxxx is used
			}

			if (targetObject != null)
			{
				interactObj = (Interactable)targetObject.GetComponent<Interactable>();
			}
		}
コード例 #2
0
ファイル: Chara2_Player.cs プロジェクト: voidserpent/rpgbase
		private void InteractWith(Interactable obj)
		{
			// first check what it is before calling the OnInteract actions
			//bool wasItemOrDrop = false;
			GameObject destroyItem = null;

			RPGLootDrop drop = (obj is RPGLootDrop ? obj as RPGLootDrop : null);
			
			if (drop != null)
			{	// just in case the item lands on the player before the "drop" component is removed
				if (drop.loot == null) drop = null;
			}

			if (drop != null)
			{
				//wasItemOrDrop = true;
				destroyItem = obj.gameObject;

				// find what items the drop offers and update the player as needed
				for (int i = 0; i < drop.loot.rewards.Count; i++)
				{
					if (drop.loot.rewards[i].count == 0f) continue;

					if (drop.loot.rewards[i].type == RPGLoot.Reward.RewardType.Currency)
					{
						_actor.currency += (int)drop.loot.rewards[i].count;
					}
					else if (drop.loot.rewards[i].type == RPGLoot.Reward.RewardType.Attribute)
					{
						RPGAttribute att = _actor.ActorClass.GetAttribute(drop.loot.rewards[i].guid);
						if (att != null) att.Value += drop.loot.rewards[i].count;
					}
					else if (drop.loot.rewards[i].type == RPGLoot.Reward.RewardType.Item)
					{
						RPGItem item = UniRPGGlobal.DB.GetItem(drop.loot.rewards[i].guid);
						if (item != null) _actor.AddToBag(item, (int)drop.loot.rewards[i].count);
					}
				}
			}
			else
			{
				// if an item, then attempt to pick it up
				RPGItem item = (obj is RPGItem ? obj as RPGItem : null);
				if (item != null)
				{
					//wasItemOrDrop = true;
					destroyItem = item.gameObject;

					// get a reference to the item's prefab and save that to the bag. do not save item instances in the bag!
					if (UniRPGGlobal.DB.RPGItems.ContainsKey(item.prefabId.Value))
					{
						_actor.AddToBag(UniRPGGlobal.DB.RPGItems[item.prefabId.Value], 1);
					}
				}
			}

			//if (!wasItemOrDrop) UniRPGGameController.ExecuteActions(obj.onInteractActions, obj.gameObject, null, gameObject, null, null, false);
			UniRPGGameController.ExecuteActions(obj.onInteractActions, obj.gameObject, null, gameObject, null, null, false);
			if (destroyItem != null) Destroy(destroyItem);
		}