void OnMouseDrag() { if (this.IsDisabled()) { return; } //calculate new dragged position Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset; transform.position = curPosition; updateRubberBand(); //plot trajectory Vector3 diff = initialPosition - transform.position; Shot.ShotParams sParams = Manager.instance.nextShots [Manager.instance.nextShotIndex]; trajectoryMngr.PlotTrajectory(initialPosition, diff * velocityMultiplier, sParams); ballToSoohtHintRenderer.color = sParams.GetColor();; AudioManager.StartSlingshot(); if (debugPrints) { print("curScreenPoint - " + curScreenPoint + "\ncurPosition - " + curPosition); } }
// Use this for initialization void Awake() { if (instance == null) { instance = this; } Vector3 positionFix = new Vector3(0, -2, 0); endPanel.SetActive(false); initWorld(hexRadius); if (PhotonNetwork.inRoom) { playerId = (int)PhotonNetwork.player.customProperties["playerId"]; Vector3 pos = Quaternion.Euler(0, 120 * this.playerId, 0) * Camera.main.transform.position; Camera.main.transform.position = pos; Camera.main.transform.rotation = Quaternion.LookRotation(positionFix - Camera.main.transform.position, Vector3.up); } else { playerId = 0; Camera.main.transform.rotation = Quaternion.LookRotation(positionFix - Camera.main.transform.position, Vector3.up); } this.setFlagColors(); this.setCurrentFlag(); nextBallsWidgetScript = nextBallsWidget.GetComponent <NextBallsWidget> (); nextShots = new Shot.ShotParams[3]; for (int i = 0; i < nextShots.Length; ++i) { nextShots[i] = new Shot.ShotParams(); } turnsText.text = string.Format("{0}", numTurns); }
public Shot.ShotParams GetNextShot() { Shot.ShotParams next = this.nextShots[this.nextShotIndex]; this.nextShots[this.nextShotIndex] = new Shot.ShotParams(); this.nextShotIndex = (this.nextShotIndex + 1) % this.nextShots.Length; //update widget nextBallsWidgetScript.dropNextBall(); return(next); }
void OnMouseUp() { ballToSoohtHintRenderer.color = Color.clear; if (this.IsDisabled()) { return; } //calculate drag vector Vector3 diff = initialPosition - transform.position; if (debugPrints) { print("initial = " + initialPosition + "\ncurrent position = " + transform.position + "\nvec = " + diff + "\ndist = " + diff.magnitude); } //snap draggable back transform.position = initialPosition; updateRubberBand(); //hide guide trajectoryMngr.hideTrajectory(); //shoot AudioManager.EndSlingshot(); if (diff.y > 0) { Shot.ShotParams nextShot = Manager.instance.GetNextShot(); if (PhotonNetwork.inRoom) { PhotonNetwork.RPC(photonView, "shoot", PhotonTargets.All, false, new object[] { diff *velocityMultiplier, (int)nextShot.type, (int)nextShot.color, nextShot.timeToLive }); } else { shoot(diff * velocityMultiplier, (int)nextShot.type, (int)nextShot.color, nextShot.timeToLive); } } }
//trajectory mapping public void PlotTrajectory(Vector3 start, Vector3 velocity, Shot.ShotParams shotParams) { if (Vector3.Distance(velocity, lastVelocity) > redrawThreshhold) { lastVelocity = velocity; trajectory.SetPosition(0, start); trajectory.SetPosition(1, start + (velocity * directionIndecatorLengthMultiplier)); if (velocity.y > 0) { trajectory.SetColors(shotParams.GetColor(), shotParams.GetColor()); } else { hideTrajectory(); } } }
private void ShootColor(Vector3 direction, Shot.ShotParams shotParams) { // float height = direction.y; // direction.y = 0; // float distance = direction2d.magnitude; // float angle = spitAngle * Mathf.Deg2Rad; // Vector3 direction3d = new Vector3 (direction2d.x, distance * Mathf.Tan (angle), direction2d.y); // distance += height / Mathf.Tan (angle); // float speed = Mathf.Sqrt (distance * Physics.gravity.magnitude / Mathf.Sin (2 * angle)); // Vector3 direction3d = new Vector3 (direction2d.x, spitHeight, direction2d.y); // Vector3 velocity = spitSpeed * direction; Shot newShot = Object.Instantiate(shotPrefab).GetComponent <Shot> (); newShot.InitShot(new Shot.ShotParams(shotParams.type, shotParams.color, shotParams.timeToLive - 1)); var shotRigidBody = newShot.GetComponent <Rigidbody> (); shotRigidBody.transform.position = this.transform.position + new Vector3(0, muzzleOffset, 0); shotRigidBody.velocity = spitSpeed * direction; }
private void SetBallVisuals(int index, Shot.ShotParams param) { balls[2].GetComponent <Image>().color = param.GetColor(); }
public void EatColor(Shot.ShotParams shotParams) { savedShotParams = shotParams; animator.SetTrigger (EAT_TRIGGER); }
// Use this for initialization void Awake() { if (instance == null) { instance = this; } Vector3 positionFix = new Vector3(0, -2, 0); endPanel.SetActive(false); initWorld (hexRadius); if (PhotonNetwork.inRoom) { playerId = (int)PhotonNetwork.player.customProperties["playerId"]; Vector3 pos = Quaternion.Euler(0, 120 * this.playerId, 0) * Camera.main.transform.position; Camera.main.transform.position = pos; Camera.main.transform.rotation = Quaternion.LookRotation(positionFix - Camera.main.transform.position, Vector3.up); } else { playerId = 0; Camera.main.transform.rotation = Quaternion.LookRotation(positionFix - Camera.main.transform.position, Vector3.up); } this.setFlagColors(); this.setCurrentFlag(); nextBallsWidgetScript = nextBallsWidget.GetComponent<NextBallsWidget> (); nextShots = new Shot.ShotParams[3]; for (int i = 0; i < nextShots.Length; ++i) { nextShots[i] = new Shot.ShotParams(); } turnsText.text = string.Format("{0}", numTurns); }
public void EatColor(Shot.ShotParams shotParams) { savedShotParams = shotParams; animator.SetTrigger(EAT_TRIGGER); }