Hello there!
I am currently making a survival game. I made a script that would spawn trees randomly (with raycasts) across the map. And I attempted to make a script on that would chop down trees:
using UnityEngine;
using System.Collections;
public class ChoppingTrees : MonoBehaviour {
public int Chopcounter;
float Distance;
public Transform PlayerPos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Distance = Vector3.Distance (FindObjectOfType<PlayerControlsMovement> ().PlayerPosition, transform.position);
if (Chopcounter == 5 && Distance < 3) {
Debug.Log ("You have chopped a tree!");
}
}
void OnMouseDown (){
Chopcounter++;
}
}
(Btw. PlayerPos is just a Vector3 that stores the players position and updates it every frame)
Now, this script does kind of work, although it makes my fps drop to about 2. Anyone know how I should go about doing this? Thanks in advance!