public void Equip(Equipable new_item) { // equip the item Debug.Log("equiping - " + new_item.name); if (item) { manager.strength -= item.strength; manager.mana -= item.mana; Destroy(item.gameObject); } item = Instantiate(new_item); Vector3 rot = item.transform.localEulerAngles; item.transform.SetParent(transform); item.transform.localPosition = item.transform.position; item.transform.localEulerAngles = rot; foreach (var coll in item.GetComponentsInChildren <Collider2D>()) { ignore.IgnoreCollider(coll); } var collider = item.GetComponent <Collider2D>(); if (collider) { ignore.IgnoreCollider(collider); } manager.strength += item.strength; manager.mana += item.mana; }
public bool SpawnInWorld(Vector3 position, Quaternion rotation, Vector3 velocity) { Deactivate(); RemoveFromWorld(); equipable = (Equipable)Instantiate(equipablePrefab, position, rotation); equipable.SetEquipment(this); Rigidbody rigidbody = equipable.GetComponent <Rigidbody>(); if (rigidbody != null) { rigidbody.velocity = velocity; } return(true); }
public bool SpawnInWorld(Vector3 position, Quaternion rotation, Vector3 velocity) { Deactivate(); RemoveFromWorld(); equipable = (Equipable)Instantiate(equipablePrefab, position, rotation); equipable.SetEquipment(this); Rigidbody rigidbody = equipable.GetComponent<Rigidbody>(); if (rigidbody != null) rigidbody.velocity = velocity; return true; }
// Update is called once per frame void Update() { var mousePos3d = Input.mousePosition; mousePos3d.z = Mathf.Abs(Camera.main.transform.position.z); var mousePos = Camera.main.ScreenToWorldPoint(mousePos3d); character.SetTarget(mousePos); if (cursor != null) { cursor.transform.position = Input.mousePosition; } moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); if (Input.GetButton("Shoot")) { if (magicWand != null) { magicWand.Shoot(true); } } if (Input.GetButtonDown("Teleport")) { if (boots != null) { boots.Teleport(mousePos); } } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hits = Physics.RaycastAll(ray, 100, equipableMask); Equipable equipable = null; foreach (var hit in hits) { var eq = hit.collider.gameObject.GetComponent <Equipable>(); if (eq == null || !eq.readyToPickUp) { continue; } equipable = eq; if (eq == lastHovered) { break; } } if (equipable != lastHovered) { if (lastHovered != null) { lastHovered.UnHover(); } lastHovered = equipable; } if (equipable != null) { var closeEnough = Vector2.Distance(transform.position, equipable.transform.position) < UseRange; equipable.Hover(closeEnough); if (Input.GetButtonDown("Pick Up") && closeEnough && !equipable.blocked) { equipable.Equip(); MagicWand wand = equipable.GetComponent <MagicWand>(); if (wand != null) { EquipWand(wand); } LevelExit exit = equipable.GetComponent <LevelExit>(); if (exit != null) { exit.Exit(); } Key key = equipable.GetComponent <Key>(); if (key != null) { key.PickUp(); key.transform.position = keyParent.position; key.transform.rotation = keyParent.rotation; key.transform.parent = keyParent; } Potion potion = equipable.GetComponent <Potion>(); if (potion != null) { potion.PickUp(); } Boots boots = equipable.GetComponent <Boots>(); if (boots != null) { EquipBoots(boots); } } if (cursor != null) { cursor.SetInteract(true, closeEnough, !equipable.blocked); } } else { if (cursor != null) { cursor.SetInteract(false, false, false); } } if (invincible) { var color = Color.red; color.a = 0.75f + 0.25f * Mathf.Cos((Time.time - lastHurt) * 5.0f); sprite.color = color; } if (wasInvincible && !invincible) { sprite.color = origColor; } wasInvincible = invincible; }