void checkPos() { if (GetComponent <LineRenderer>()) { return; } Vector3 pos = GetComponent <Transform>().position; if (pos.x > Global.Instance.MaxCameraBounds.x || pos.y > Global.Instance.MaxCameraBounds.y || pos.x < Global.Instance.MinCameraBounds.x || pos.y < Global.Instance.MinCameraBounds.y) { Signals.DestroyObjReq(); Destroy(gameObject); } }
void Update() { pos = GetComponent <Transform>().position; Global.Instance.TuggerPos = pos; if (Input.GetMouseButtonDown(1)) { active = true; } else if (Input.GetMouseButtonUp(1)) { active = false; } if (active) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GetComponent <Transform>().position = ray.GetPoint(0f); } if (grabbedObjs.Count > 0) { foreach (GameObject obj in grabbedObjs.ToArray()) { if (obj == null) { grabbedObjs.Remove(obj); return; } if (obj.GetComponent <Rigidbody2D>().gravityScale != 0) { obj.GetComponent <Rigidbody2D>().gravityScale = 0; } obj.GetComponent <Rigidbody2D>().position = Vector3.Lerp(obj.GetComponent <Transform>().position, pos, Time.deltaTime * force); if ((obj.GetComponent <Transform>().position - pos).sqrMagnitude <= 94.65f) //95 { if (obj.GetComponent <Obj>().isCorrupted) { Global.Instance.Health -= 1; } Signals.DestroyObjReq(); grabbedObjs.Remove(obj); GameObject.Destroy(obj); } } } }