public void shoot() { GameObject bala = Instantiate(balaPrefab, cañon.position, cañon.rotation); balaNormal script = bala.GetComponent <balaNormal>(); if (script != null) { script.speed = 0.5f; } }
public void shoot() { GameObject bala = Instantiate(balaPrefab, cañon.position, cañon.rotation); //para acceder a un componente de un objeto, usamos GetComponent //Recuerdo comprobar siempre si el retorno no es nulo,antes de usar la variable balaNormal script = bala.GetComponent <balaNormal>(); if (script != null) { script.speed = 0.5f; } }