Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tree Chopping - Things you'll need.
- // This will check if you hit something by casting a circle in front of you. Variables aren't correct but its something like that
- // it'll tell you. Put this in your Player.cs script.
- RaycastHit2D ray = Physics2D.CircleCast (transform.position, radius, range);
- // Check if you hit a tree and then tell the tree you want to gain a resource by using its GainResource () function.
- void OnTriggerEnter2D (Collider col) {
- if (col.tag == "Tree") {
- col.transform.SendMessage ("GainResource");
- }
- }
- // Your tree will need something like this.
- public int totalResource = 5;
- int currentResouce;
- void Start () {
- currentResource = totalResource;
- }
- void GainResource () {
- if (currentResource > totalResource) {
- // Get your player here and send them the resource.
- GameObject Player = GameObject.FindGameObjectWithTag ("Player");
- player.GetComponent<ResourceController>().IncreaseWood(1);
- } else {
- DestroyTree();
- }
- }
- void DestroyTree () {
- Destroy(gameObject);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement