public string showing = "Show Slingshot"; //FollowCam Mode private void Start() { S = this; level = 0; levelMax = castles.Length; StartLevel(); }
private void Update() { if (!aimingMode) { return; } //get mouse position Vector3 mousePos2D = Input.mousePosition; mousePos2D.z = -Camera.main.transform.position.z; Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D); //count vec difference between launchPos and mousePos3D Vector3 mouseDelta = mousePos3D - launchPos; //limit mouseDelta value to slingshot collider float maxMagnitude = this.GetComponent <SphereCollider>().radius; if (mouseDelta.magnitude > maxMagnitude) { mouseDelta.Normalize(); mouseDelta *= maxMagnitude; } //Move projectile to new position Vector3 projPos = launchPos + mouseDelta; projectile.transform.position = projPos; if (Input.GetMouseButtonUp(0)) { aimingMode = false; projectileRigidbody.isKinematic = false; projectileRigidbody.velocity = -mouseDelta * velocityMultiplier; FollowCam.POI = projectile; projectile = null; SlingshotShooter.ShotFired(); ProjectileLine.S.poi = projectile; } }