public override void Update() { if (nextpos != null) { nextpos = null; } if (hold.placable) { Vector3 vector = Camera.main.ScreenToWorldPoint(Input.mousePosition) - parent.transform.position; vector.z = 0; if (vector.magnitude > 2) { vector = vector.normalized * 2 + parent.transform.position; } else { vector = Camera.main.ScreenToWorldPoint(Input.mousePosition); } RaycastHit2D raycast = Physics2D.Raycast(vector, Vector2.zero, 50, LayerMask.GetMask("Case")); if (raycast.collider != null) { if (raycast.collider.GetComponent(typeof(Case)) != null && raycast.collider.transform.childCount == 0) { nextpos = raycast.collider.gameObject; hover.transform.position = nextpos.transform.position; hover.SetActive(true); } } if (nextpos == null) { hover.SetActive(false); } if (nextpos != null && !(hold.GetComponent(typeof(Special)) as Special).typesAccept.Contains((nextpos.GetComponent(typeof(Case)) as Case).type)) { nextpos = null; hover.GetComponent <SpriteRenderer>().color = new Color(1, 0, 0); } else { hover.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1); } } else { hover.SetActive(false); } }
public Hold(Controller parent, Special hold) : base(parent) { parent.audio.PlayOneShot((AudioClip)Resources.Load("Sound/" + ((Random.value * 2 > 1) ? "Hold1" : "Hold2"))); if (hold.transform.childCount > 0 && hold.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>() != null) { hold.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0); } else if (hold.transform.childCount > 0) { Object.Destroy(hold.transform.GetChild(0).gameObject); } this.hold = hold; this.hold.GetComponent <Collider2D>().enabled = false; hold.transform.SetParent(parent.transform); hold.transform.localPosition = new Vector3(0, 0.8f); hold.GetComponent <Rigidbody2D>().isKinematic = true; lastSorting = hold.GetComponent <SpriteRenderer>().sortingOrder; hold.GetComponent <SpriteRenderer>().sortingOrder = 4; if (hover == null) { hover = Object.Instantiate(Resources.Load <GameObject>("Case/hover"), Vector3.zero, Quaternion.identity); } hover.SetActive(false); }
public void OnPointerClick(PointerEventData eventData) { if (m_weapon.weapon_kind == 0) { Normal.GetComponent <Image>().sprite = m_weapon.image; m_config.m_player.weapon_Normal = m_weapon.weapon_prefab; } else if (m_weapon.weapon_kind == 1) { Storing.GetComponent <Image>().sprite = m_weapon.image; m_config.m_player.weapon_Storing = m_weapon.weapon_prefab; } else if (m_weapon.weapon_kind == 2) { Special.GetComponent <Image>().sprite = m_weapon.image; m_config.m_player.weapon_Special = m_weapon.weapon_prefab; } }