Hello
I’m trying change gravity scale of a prefab programatically. I have 2 prefabs, these prefabs has tag(“Enemies”) and RigidBody2D component also, I want to change gravity by C# script.
How can I do ?
I’m trying this.
public class Score : MonoBehaviour {
public int count;
public GUIText txt;
private GameObject[] enemy;
// Use this for initialization
void Start () {
txt.text = count.ToString();
enemy = GameObject.FindGameObjectsWithTag("Enemies");
}
// Update is called once per frame
void Update () {
aumentaDificuldade();
}
public void countIncrement(){
count++;
txt.text = count.ToString();
}
private void aumentaDificuldade(){
if(count > 10){
for(int x = 0; x < enemy.Length; x++){
enemy[x].GetComponent<Rigidbody2D>().gravityScale++;
}
//enemy.GetComponent<Rigidbody2D>().gravityScale++;
}
}
}