Have problem with a localscale variable

Ive wrote a simple code than spawns a plane with a bar texture and its local scale x shoud decrease, when trigger enters collider, but instead it decreases localscale from a bar prefrab! Thanks for any help.

using UnityEngine;
using System.Collections;

public class wall : MonoBehaviour {

public float WallHp = 5f;
public float wallDmgOnCoL = 1f;
public GameObject bar;
// Use this for initialization
void Start () 
{
	Instantiate(bar,new Vector3(transform.position.x,transform.position.y+20f,transform.position.z),Quaternion.Euler(-90,90,0));
 	
}

void OnTriggerEnter(Collider collision)
{
	WallHp = WallHp - wallDmgOnCoL;
	bar.transform.localScale -= new Vector3(1f, 0, 0);
	
}



// Update is called once per frame
void Update () 
{
	
	if(WallHp <= 0)
	{
		Destroy(gameObject);

	}

}

}

You are changing the actual prefab when you change the scale. It sounds like you want to change the local reference of it you made, but you aren’t storing it. You need to store the result of Instantiating and then change the scale of that object.

public float WallHp = 5f;
public float wallDmgOnCoL = 1f;
public GameObject barPrefab
public GameObject bar;
// Use this for initialization
void Start () 
{
    bar = Instantiate(barPrefab,new Vector3(transform.position.x,transform.position.y+20f,transform.position.z),Quaternion.Euler(-90,90,0));
 
}
 
void OnTriggerEnter(Collider collision)
{
    WallHp = WallHp - wallDmgOnCoL;
    bar.transform.localScale -= new Vector3(1f, 0, 0);
 
}
 
 
 
// Update is called once per frame
void Update () 
{
 
    if(WallHp <= 0)
    {
       Destroy(gameObject);
 
    }
 
}