Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class recipe : MonoBehaviour
- {
- public int itemCountWorth;//set value worth
- public int itemCount;//item counter total set public for debugging
- public int MaxItemCount;//set value in editor to determine recipe requirements
- public bool inBox;
- public string RecipeItemTagName1;//first item needed for recipe
- //TODO PLACE IN OWN COIN RECIPE SCRIPT
- public bool forCoins;
- public string RecipeResultName;
- void coinValUpdater(Collider2D item)//call this when coin update
- {
- item.transform.parent = transform;
- item.GetComponent<Rigidbody2D>().isKinematic = true;
- GameObject.FindWithTag("Player").GetComponent<coinPickUp>().screenCoinUpdate();//run screenCoinUpdate() which is located in coinPickUp.cs
- Destroy(item.gameObject);
- }
- //TODO
- void destroyChilds(Collider2D item)//destroy childs in collider2d
- {
- foreach (Transform child in transform)
- {
- GameObject.Destroy(child.gameObject);
- }
- }
- void doRecipeResult()
- {
- GameObject.FindWithTag("House").transform.position = new Vector3(0, 0, 0);
- }
- void OnTriggerStay2D(Collider2D item)
- {
- if (item.gameObject.tag == RecipeItemTagName1 && item.gameObject.layer == 8)
- {
- item.gameObject.layer = LayerMask.NameToLayer("recipeReady");//set item to layer called recipeReady
- if (item.gameObject.layer == 11 && forCoins == false)
- {//once in layer and this is true exec this line recipeReady(11))
- item.transform.parent = transform;//set object to its own parent
- item.GetComponent<Rigidbody2D>().isKinematic = true;//enable kinematic so it does not move
- itemCount = itemCount + itemCountWorth;//add up values to determine recipe status
- inBox = true;
- }
- //TODO PLACE IN OWN COIN RECIPE SCRIPT
- if (item.gameObject.layer == 11 && forCoins == true)
- {//only runs if this is for coins
- coinValUpdater(item);
- }
- //TODO
- if (itemCount == MaxItemCount && forCoins == false)
- {//code if not for coins todo, setup system
- destroyChilds(item);
- doRecipeResult();
- }
- }
- }
- void OnTriggerExit2D(Collider2D item)
- {
- //Debug.Log ("Log exit:" + item.gameObject.tag);
- if (item.gameObject.tag == "Crate" && inBox == true)
- {
- //item.gameObject.layer = LayerMask.NameToLayer ("pickedUp");
- inBox = false;
- itemCount = itemCount - itemCountWorth;
- }
- }
- }
- using UnityEngine;
- using System.Collections;
- public class recipe : MonoBehaviour
- {
- public int itemCountWorth;//set value worth
- public int itemCount;//item counter total set public for debugging
- public int MaxItemCount;//set value in editor to determine recipe requirements
- public bool inBox;
- public string RecipeItemTagName1;//first item needed for recipe
- //TODO PLACE IN OWN COIN RECIPE SCRIPT
- public bool forCoins;
- public string RecipeResultName;
- void coinValUpdater(Collider2D item)//call this when coin update
- {
- item.transform.parent = transform;
- item.GetComponent<Rigidbody2D>().isKinematic = true;
- GameObject.FindWithTag("Player").GetComponent<coinPickUp>().screenCoinUpdate();//run screenCoinUpdate() which is located in coinPickUp.cs
- Destroy(item.gameObject);
- }
- //TODO
- void destroyChilds(Collider2D item)//destroy childs in collider2d
- {
- foreach (Transform child in transform)
- {
- GameObject.Destroy(child.gameObject);
- }
- }
- void doRecipeResult()
- {
- GameObject.FindWithTag("House").transform.position = new Vector3(0, 0, 0);
- }
- void OnTriggerStay2D(Collider2D item)
- {
- if (item.gameObject.tag == RecipeItemTagName1 && item.gameObject.layer == 8)
- {
- item.gameObject.layer = LayerMask.NameToLayer("recipeReady");//set item to layer called recipeReady
- if (item.gameObject.layer == 11 && forCoins == false)
- {//once in layer and this is true exec this line recipeReady(11))
- item.transform.parent = transform;//set object to its own parent
- item.GetComponent<Rigidbody2D>().isKinematic = true;//enable kinematic so it does not move
- itemCount = itemCount + itemCountWorth;//add up values to determine recipe status
- inBox = true;
- }
- //TODO PLACE IN OWN COIN RECIPE SCRIPT
- if (item.gameObject.layer == 11 && forCoins == true)
- {//only runs if this is for coins
- coinValUpdater(item);
- }
- //TODO
- if (itemCount == MaxItemCount && forCoins == false)
- {//code if not for coins todo, setup system
- destroyChilds(item);
- doRecipeResult();
- }
- }
- }
- void OnTriggerExit2D(Collider2D item)
- {
- //Debug.Log ("Log exit:" + item.gameObject.tag);
- if (item.gameObject.tag == "Crate" && inBox == true)
- {
- //item.gameObject.layer = LayerMask.NameToLayer ("pickedUp");
- inBox = false;
- itemCount = itemCount - itemCountWorth;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement