i am new to Unity so i really trying hard to learn.
i created a function in a new class called applescript
if i want to create collision with a new element for example : a coin
i need to create a new class? or i should attach the same script for every coin\apple i spawn?
you can use your script for other gameobject. But you dont need attach the script to every apple. Just create prefab. Drag&Drop your "aplle " on this prefab. And then you can just spawn the clones of the prefab.
you can make your script universal. I mean, use public variables. So for your script, something like.
public float staminaChange;
public string whatObject;
void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == "Player") {
GameControl.control.stamina += staminaChange;
Debug.Log(whatObject);
Destroy(gameObject);
}
}
and now, you can attach the script to gameobject and adjust it.