private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { DemoScript.ReloadCurrentScene(); return; } else if (Input.GetMouseButton(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { Vector3 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Camera.main.orthographic) { worldPos.z = 0.0f; } if (points.Count == 0 || (points[points.Count - 1] - worldPos).magnitude > 8.0f) { points.Add(worldPos); Script.Trigger(points, SplineToggle.isOn); } } }
private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { DemoScript.ReloadCurrentScene(); return; } CharacterController controller = GetComponent <CharacterController>(); transform.Rotate(0, Input.GetAxis("Horizontal") * RotateSpeed, 0); Vector3 forward = transform.TransformDirection(Vector3.forward); float curSpeed = Speed * Input.GetAxis("Vertical"); controller.SimpleMove(forward * curSpeed); if (Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.KeypadPlus)) { NextSpell(); } else if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus)) { PreviousSpell(); } LightningSpellScript spell = Spells[spellIndex]; if (Input.GetButton("Fire1") && (spellMouseButtonDown || !Input.GetMouseButton(0) || GuiElementShouldPassThrough())) { // Debug.Log("Casting spell " + spell.ToString()); if (spell.SpellStart != null && spell.SpellStart.GetComponent <Rigidbody>() == null) { spell.SpellStart.transform.position = rightHand.transform.position; } if (Input.GetMouseButton(0)) { spellMouseButtonDown = true; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Vector3 rayEnd; // send out a ray from the mouse click - if it collides with something we are interested in, alter the ray direction if (Physics.Raycast(ray, out hit, spell.MaxDistance, spell.CollisionMask)) { rayEnd = hit.point; } else { rayEnd = ray.origin + (ray.direction * spell.MaxDistance); } spell.Direction = (rayEnd - spell.SpellStart.transform.position).normalized; } else { spellMouseButtonDown = false; spell.Direction = gameObject.transform.forward; } spell.CastSpell(); } else { spellMouseButtonDown = false; spell.StopSpell(); } }