I want to change the material of a prefab every time damage is equal 2, however this changes every single instance of the prefab.
This the script in the prefab
public Material[] materials;
public Renderer rend;
void start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
damage = 1;
}
void Update()
{
if (damage == 2)
{
rend.material = materials[0];
}
}
this one is the player’s script that instantiate the prefabs.
public Rigidbody ball;
private void Shotter()
{
if (Input.GetMouseButton(0) && ballSpeed< 50.0f)
{
ballSpeed += 25.0f * Time.deltaTime;
//Debug.Log(ballSpeed);
filler.fillAmount += 0.5f * Time.deltaTime;
}
if (Input.GetMouseButtonUp(0) && ballNumber < ballNumberLimit)
{
Rigidbody ballInstance;
ballInstance = Instantiate(ball, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
cubes.Add(ballInstance);
ballInstance.velocity = barrelEnd.forward * ballSpeed;
ballSpeed = 0.0f;
filler.fillAmount = 0.0f;
ballNumber += 1;
}
}