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);
}
}
}