private void Start() { part0 = transform.Find("Part0").GetComponent <ComponentPart>(); part1 = transform.Find("Part1").GetComponent <ComponentPart>(); lifebar = transform.Find("Lifebar").GetComponent <Image>(); componentImage = transform.Find("Component").GetComponent <Image>(); audioSource = GetComponent <AudioSource>(); var canvas = FindObjectOfType <Canvas>(); inventory = canvas.GetComponentInChildren <Inventory>(); ship = canvas.GetComponentInChildren <Ship>(); Flip(); UpdatePart(ref part0, 0); UpdatePart(ref part1, 1); if (parts.Length > 2) { parts = parts.Take(2).ToArray(); } componentImage.sprite = Item.GetSpriteForItem(componentType); var rt = lifebar.transform as RectTransform; lifebarWidth = rt.rect.width; Health = Globals.Instance.shipComponentHealth[Array.IndexOf(Item.ComponentTypes, componentType)]; }
private void UpdatePart(ref ComponentPart part, int index) { if (parts.Length > index) { part.itemType = parts[index]; part.UpdateSprite(); } else { Destroy(part.gameObject); part = null; } }