Im making a coin clicker game and are almost done. Because im not familiar with unity and im new with programming i want to ask how to do a thing:
- I want to make coins to fall from the air, down with the amount of clicks and click per second the player do. To get a idea of what i mean try this Cookie Clicker. When you click, cookies fall down, and if u click faster, more will fall.
**im using C#
You could just create a prefab of a GameObject that has the coin image on it.
Then just create an instance every time the player clicks:
GameObject go = (GameObject)Instantiate(prefab);
Then set the position to the position of the click:
go.transform.position = Input.mousePosition;
Of course you would need to have a rigid body(so it falls down) on the prefab as well as a script that handles when it will be destroyed,
So i made a perfab, made the rigidbody but cant get the amount of coins to increase every time i click the button. How do i connect these 2 codes
Well there are many ways to do it.
One way would be to have a GameManager class.
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public int coinCount = 0;
void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(gameObject);
return;
}
}
}
Then you can just update the count when you instance the prefab.
GameManager.instance.coinCount++;
and access the value wherever needed like this:
int coinCount = GameManager.instance.coinCount;
well lets start with the correct function names shall we
Update not update
http://www.dofactory.com/reference/csharp-coding-standards