private void InitializeGuilti() { //initialization of the ready to be thrown Guilti GuiltiToThrow.transform.position = GuiltiWaitPosition.position; slingshotState = SlingshotState.Idle; SetSlingshotLineRenderersActive(true); }
private void InitializeBird() { //initialization of the ready to be thrown bird BirdToThrow.transform.position = BirdWaitPosition.position; slingshotState = SlingshotState.Idle; SetSlingshotLineRenderersActive(true); }
private void ThrowBird(float distance, float angle) { Dashing = true; Movement.gravity = -4; Movement.velocity = new Vector2(direction.x, direction.y) * ThrowSpeed * distance; slingshotState = SlingshotState.Idle; startTouch = Vector3.zero; curTouch = Vector3.zero; jumps -= 1; if (angle >= -45 && angle < 0 || angle >= 0 && angle <= 45) { pAni.SetInteger("SwipeType", 3); } if (angle <= -145 && angle > -180 || angle > 145 && angle < 180) { pAni.SetInteger("SwipeType", 3); } if (angle > 45 && angle <= 90 || angle < -45 && angle >= -90) { pAni.SetInteger("SwipeType", 2); } if (angle < -90 && angle > -145) { pAni.SetInteger("SwipeType", 2); } }
public void OnMouseDown() { if (state == SlingshotState.Idle) { state = SlingshotState.UserPulling; } }
// Use this for initialization void Start() { maya = GameObject.Find("maya"); start = GameObject.Find("start"); finish = GameObject.Find("finish"); Camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>() as Camera; transform = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Transform>(); //set the sorting layer name for the line renderers //for the slingshot renderers this did not work so I //set the z on the background sprites to 10 //hope there's a better way around that! SlingshotLineRenderer1.sortingLayerName = "Foreground"; SlingshotLineRenderer2.sortingLayerName = "Foreground"; TrajectoryLineRenderer.sortingLayerName = "Foreground"; slingshotState = SlingshotState.Idle; SlingshotLineRenderer1.SetPosition(0, LeftSlingshotOrigin.position); SlingshotLineRenderer2.SetPosition(0, RightSlingshotOrigin.position); //pointing at the middle position of the two vectors SlingshotMiddleVector = new Vector3((LeftSlingshotOrigin.position.x + RightSlingshotOrigin.position.x) / 2, (LeftSlingshotOrigin.position.y + RightSlingshotOrigin.position.y) / 2, 0); }
protected void RopeRevert() { Vector3 leftPos = m_BallOrigLocalPosition - m_LineLeft.transform.localPosition; Vector3 rightPos = m_BallOrigLocalPosition - m_LineRight.transform.localPosition; ChangeRopePosition(leftPos, rightPos); m_SlingshotState = SlingshotState.Idle; }
protected void ShotBall() { Vector3 dir = (m_BallOrigLocalPosition - transform.localPosition).normalized; transform.GetComponent <Rigidbody>().useGravity = true; transform.GetComponent <Rigidbody>().AddForce(dir * m_SlingFactor, ForceMode.Impulse); m_SlingshotState = SlingshotState.Shotting; }
// Update is called once per frame void Update() { switch (slingshotState) { case SlingshotState.Idle: InitializeBird(); DisplaySlingshotLineRenderers(); if (Input.GetMouseButtonDown(0)) { Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (birdToThrow.GetComponent <CircleCollider2D>() == Physics2D.OverlapPoint(location)) { slingshotState = SlingshotState.UserPulling; } } break; case SlingshotState.UserPulling: DisplaySlingshotLineRenderers(); if (Input.GetMouseButton(0)) { Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); location.z = 0f; if (Vector3.Distance(location, slingshotMiddleVector) > 1.5f) { var maxPosition = (location - slingshotMiddleVector).normalized * 1.5f + slingshotMiddleVector; birdToThrow.transform.position = maxPosition; } else { birdToThrow.transform.position = location; } var distance = Vector3.Distance(slingshotMiddleVector, birdToThrow.transform.position); DisplaySlingshotTrajectoryLineRenderer(distance); } else { SetTrajectoryLineRendererActive(true); timeSinceThrown = Time.time; float distance = Vector3.Distance(slingshotMiddleVector, birdToThrow.transform.position); if (distance > 1) { SetSlingshotLineRendererActive(false); slingshotState = SlingshotState.BirdFlying; ThrowBird(distance); } else { birdToThrow.transform.positionTo(distance / 10, birdWaitPosition.position); InitializeBird(); } } break; } }
void Start() { slingshotState = SlingshotState.Idle; References.controller = GetComponent <Controller2D> (); TrajectoryLineRenderer.sortingLayerName = "2"; Movement.maxJumpVelocity = Mathf.Abs(Movement.gravity) * Movement.timeToJumpApex; Movement.minJumpVelocity = Mathf.Sqrt(2 * Mathf.Abs(Movement.gravity) * Movement.minJumpHeight); References.audio = GetComponent <AudioSource>(); UpdateHealthBar(); }
private void InitializePill() { //initialization of the ready to be thrown pill if (PillToThrow == null) { return; } PillToThrow.transform.position = PillWaitPosition.position; slingshotState = SlingshotState.Idle; SetSlingshotLineRenderersActive(true); }
// Start is called before the first frame update void Start() { if (level == null) { level = FindObjectOfType <Level>(); } state = SlingshotState.Idle; //TODO possibly move somewhere better birdToThrow = level.Birds[birdArrayIndex]; }
IEnumerator ReloadRoutine() { birdToThrow.transform.DOMove(launchPoint.transform.position, reloadTime); float timeToWait = Time.time + reloadTime; while (timeToWait > Time.time) { yield return(null); } state = SlingshotState.Idle; }
// Use this for initialization void Start() { TrajectoryLineRenderer.sortingLayerName = "Foreground"; slingshotState = SlingshotState.Idle; SlingshotLineRenderer1.SetPosition(0, LeftSlingshotOrigin.position); SlingshotLineRenderer2.SetPosition(0, RightSlingshotOrigin.position); //pointing at the middle position of the two vectors SlingshotMiddleVector = new Vector3((LeftSlingshotOrigin.position.x + RightSlingshotOrigin.position.x) / 2, (LeftSlingshotOrigin.position.y + RightSlingshotOrigin.position.y) / 2, 0); }
private void InitializeBird() { //initialization of the ready to be thrown bird BirdToThrow.transform.position = BirdWaitPosition.position; slingshotState = SlingshotState.Idle; SetSlingshotLineRenderersActive(true); transform.position = Vector3.Lerp(transform.position, new Vector3(-5, 1.49F, -10), f); // Camera.orthographicSize = 8 ; }
private void InitializeBird() { birdToThrow.transform.position = birdWaitPosition.position; slingShootState = SlingshotState.Idle; object[] array = Global.brokenBotList.ToArray(); if (array != null && array.Length > 0) { for (int i = 0; i < array.Length; i++) { ((Explodable)array[i]).deleteFragments(); } } }
void Awake() { slingShootLineRenderer1.sortingLayerName = "Foreground"; slingShootLineRenderer2.sortingLayerName = "Foreground"; trajectoryLineRenderer.sortingLayerName = "Foreground"; slingShootState = SlingshotState.Idle; slingShootLineRenderer1.SetPosition(0, leftSlingShootOrigin.position); slingShootLineRenderer2.SetPosition(0, rightSlingShootOrigin.position); slingShootMiddleVector = new Vector3((leftSlingShootOrigin.position.x + rightSlingShootOrigin.position.x) / 2, (leftSlingShootOrigin.position.y + rightSlingShootOrigin.position.y) / 2, 0); }
// Use this for initialization void Start() { SlingshotLineRenderer1.sortingLayerName = "Foreground"; SlingshotLineRenderer2.sortingLayerName = "Foreground"; TrajectoryLineRenderer.sortingLayerName = "Foreground"; SlingshotLineRenderer1.SetPosition(0, LeftCatapultOrigin.position); SlingshotLineRenderer2.SetPosition(0, RightCatapultOrigin.position); slingshotState = SlingshotState.Idle; CatapultMiddleVector = new Vector3((LeftCatapultOrigin.position.x + RightCatapultOrigin.position.x) / 2, (LeftCatapultOrigin.position.y + RightCatapultOrigin.position.y) / 2, 0); }
private void GetNextBird() { birdArrayIndex++; if (birdArrayIndex >= level.Birds.Length) { //no more birds //game over (wait for score) return; } //assign next bird birdToThrow = level.Birds[birdArrayIndex]; state = SlingshotState.Reloading; StartCoroutine(ReloadRoutine()); }
private void InitializeBird() { //initialization of the ready to be thrown bird BirdToThrow.transform.position = BirdWaitPosition.position; if (isAngleFrozen == true) { BirdToThrow.transform.position = new Vector3(BirdToThrow.transform.position.x, -2.5f, BirdToThrow.transform.position.z); } else if (isStrenghtFrozen == true) { BirdToThrow.transform.position = new Vector3(-5.0f, BirdToThrow.transform.position.y, BirdToThrow.transform.position.z); } slingshotState = SlingshotState.Idle; SetSlingshotLineRenderersActive(true); }
void Start() { m_FoodSprite = this.gameObject.GetComponent <SpriteRenderer>().sprite; m_BallOrigLocalPosition = transform.localPosition; m_SlingshotState = SlingshotState.Idle; ChangeRopePosition(); if (m_MovingSensitivity <= 0.0f) { m_MovingSensitivity = 1.0f; } m_As = GetComponent <AudioSource>(); }
// Use this for initialization void Start() { //set the sorting layer name for the line renderers //for the slingshot renderers this did not work so I //set the z on the background sprites to 10 //hope there's a better way around that! SlingshotLineRenderer1.sortingLayerName = "Foreground"; SlingshotLineRenderer2.sortingLayerName = "Foreground"; TrajectoryLineRenderer.sortingLayerName = "Foreground"; slingshotState = SlingshotState.Idle; InitSlingShotStringsPosition(); //pointing at the middle position of the two vectors SlingshotMiddleVector = new Vector3((LeftSlingshotOrigin.position.x + RightSlingshotOrigin.position.x) / 2, (LeftSlingshotOrigin.position.y + RightSlingshotOrigin.position.y) / 2, 0); }
void Update() { if (Input.touchCount <= 0 || Input.touchCount > 1) { m_SlingshotState = SlingshotState.Idle; return; } if (Input.touches[0].phase == TouchPhase.Began) { //version 1 if (m_SlingshotState == SlingshotState.Idle) { Vector2 touchingPos = new Vector2(Input.touches[0].position.x, Input.touches[0].position.y); if (IsTouchingBall(touchingPos)) { print("touching ball"); m_SlingshotState = SlingshotState.Ready; } } } if (Input.touches[0].phase == TouchPhase.Moved) { if (m_SlingshotState == SlingshotState.Ready) { ChangeBallPosition(); ChangeRopePosition(); //m_As.Play(); } else { m_SlingshotState = SlingshotState.Idle; } } if (Input.touches[0].phase == TouchPhase.Ended) { if (m_SlingshotState == SlingshotState.Ready) { ShotBall(); RopeRevert(); } } }
// Use this for initialization void Start() { //set the sorting layer name for the line renderers //for the slingshot renderers this did not work so I //set the z on the background sprites to 10 //hope there's a better way around that! SlingshotLineRenderer1.sortingLayerName = "Foreground"; SlingshotLineRenderer2.sortingLayerName = "Foreground"; TrajectoryLineRenderer.sortingLayerName = "Foreground"; slingshotState = SlingshotState.Idle; SlingshotLineRenderer1.SetPosition(0, LeftSlingshotOrigin.position); SlingshotLineRenderer2.SetPosition(0, RightSlingshotOrigin.position); //pointing at the middle position of the two vectors SlingshotMiddleVector = new Vector3((LeftSlingshotOrigin.position.x + RightSlingshotOrigin.position.x) / 2, (LeftSlingshotOrigin.position.y + RightSlingshotOrigin.position.y) / 2, 0); }
private IEnumerator StopSlingshot() { if (slingshotState != SlingshotState.Pulling) { yield break; } ; slingshotState = SlingshotState.Shooting; Debug.Log("Playing slingshotShoot"); source.clip = slingshotShoot; source.loop = false; source.Play(); yield return(new WaitForSeconds(slingshotShoot.length)); slingshotState = SlingshotState.Resting; }
private void Awake() { Global.count = 0; Global.birdCount = 0; ribbonPullSoundPlayed = false; trajectoryLineRenderer.sortingLayerName = "Foreground"; slingShootState = SlingshotState.Idle; slingShootLineRenderer1.SetPosition(0, leftSlingShootOrigin.position); slingShootLineRenderer2.SetPosition(0, rightSlingShootOrigin.position); Vector3 position = leftSlingShootOrigin.position; float x = position.x; Vector3 position2 = rightSlingShootOrigin.position; float x2 = (x + position2.x) / 2f; Vector3 position3 = leftSlingShootOrigin.position; float y = position3.y; Vector3 position4 = rightSlingShootOrigin.position; slingShootMiddleVector = new Vector3(x2, (y + position4.y) / 2f, 0f); }
// working with player input and slingshot state here private void FixedUpdate() { if (Input.touchCount < 1) { if (State == SlingshotState.loaded) { arrowTransform.gameObject.SetActive(false); State = SlingshotState.empty; } return; } RaycastHit hit; switch (State) { case SlingshotState.ready: hit = ReadPlayerTouch(projectileLayer); if (hit.collider) { arrowTransform.gameObject.SetActive(true); State = SlingshotState.loaded; } break; case SlingshotState.loaded: hit = ReadPlayerTouch(launchAreaLayer); if (hit.collider) { slingshotViewTransform.LookAt(hit.point); slingshotViewTransform.Rotate(Vector3.up, 180); projectile.transform.position = hit.point; } break; default: return; } }
public void OnMouseRelease(Vector3 mousePosition) { if (state != SlingshotState.UserPulling) { return; } float distance = Vector3.Distance(launchPoint.position, birdToThrow.transform.position); if (distance > dragThreshold) { ThrowBird(distance); state = SlingshotState.BirdFlying; GetNextBird(); } else { //cancel throw //TODO Move Back to position birdToThrow.transform.position = launchPoint.position; state = SlingshotState.Idle; return; } }
void Start() { //获取LineRenderer m_LineLeft = GameObject.Find("slingshot").transform.FindChild("ropeLeft"). transform.GetComponent <LineRenderer>(); m_LineRight = GameObject.Find("slingshot").transform.FindChild("ropeRight"). transform.GetComponent <LineRenderer>(); m_FoodSprite = this.gameObject.GetComponent <SpriteRenderer>().sprite; m_BallOrigLocalPosition = transform.localPosition; m_SlingshotState = SlingshotState.Idle; m_CosPlanesAngle = Mathf.Cos(Mathf.Deg2Rad * m_PlanesAngle); m_SinPlanesAngle = Mathf.Sin(Mathf.Rad2Deg * m_PlanesAngle); ChangeRopePosition(); if (m_MovingSensitivity <= 0.0f) { m_MovingSensitivity = 1.0f; } }
// Update is called once per frame void Update() { switch (slingshotState) { case SlingshotState.Idle: //fix bird's position InitializeBird(); //display the slingshot "strings" DisplaySlingshotLineRenderers(); if (Input.GetMouseButtonDown(0)) { //get the point on screen user has tapped Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); //if user has tapped onto the bird if (BirdToThrow.GetComponent <CircleCollider2D>() == Physics2D.OverlapPoint(location)) { slingshotState = SlingshotState.UserPulling; } } break; case SlingshotState.UserPulling: DisplaySlingshotLineRenderers(); if (Input.GetMouseButton(0)) { //get where user is tapping Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); location.z = 0; //we will let the user pull the bird up to a maximum distance if (Vector3.Distance(location, SlingshotMiddleVector) > 1.5f) { //basic vector maths :) var maxPosition = (location - SlingshotMiddleVector).normalized * 1.5f + SlingshotMiddleVector; BirdToThrow.transform.position = maxPosition; } else { BirdToThrow.transform.position = location; } float distance = Vector3.Distance(SlingshotMiddleVector, BirdToThrow.transform.position); //display projected trajectory based on the distance DisplayTrajectoryLineRenderer2(distance); } else { //user has removed the tap SetTrajectoryLineRenderesActive(false); //throw the bird!!! TimeSinceThrown = Time.time; float distance = Vector3.Distance(SlingshotMiddleVector, BirdToThrow.transform.position); if (distance > 1) { SetSlingshotLineRenderersActive(false); slingshotState = SlingshotState.BirdFlying; ThrowBird(distance); } else { //not pulled long enough, so reinitiate it //distance/10 was found with trial and error :) //animate the bird to the wait position BirdToThrow.transform.positionTo(distance / 10, //duration BirdWaitPosition.transform.position). //final position setOnCompleteHandler((x) => { x.complete(); x.destroy(); InitializeBird(); }); } } break; case SlingshotState.BirdFlying: break; default: break; } }
private IEnumerator StopSlingshot() { if (slingshotState != SlingshotState.Pulling) yield break; ; slingshotState = SlingshotState.Shooting; Debug.Log ("Playing slingshotShoot"); source.clip = slingshotShoot; source.loop = false; source.Play (); yield return new WaitForSeconds (slingshotShoot.length); slingshotState = SlingshotState.Resting; }
// Update is called once per frame void Update() { switch (slingshotState) { case SlingshotState.Idle: //fix bird's position InitializeBird(); //display the slingshot "strings" DisplaySlingshotLineRenderers(); if (Input.GetMouseButtonDown(0)) { //get the point on screen user has tapped Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); //if user has tapped onto the bird if (BirdToThrow.GetComponent<CircleCollider2D>() == Physics2D.OverlapPoint(location)) { slingshotState = SlingshotState.UserPulling; } } break; case SlingshotState.UserPulling: DisplaySlingshotLineRenderers(); if (Input.GetMouseButton(0)) { //get where user is tapping Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); location.z = 0; //we will let the user pull the bird up to a maximum distance if (Vector3.Distance(location, SlingshotMiddleVector) > 1.5f) { //basic vector maths :) var maxPosition = (location - SlingshotMiddleVector).normalized * 1.5f + SlingshotMiddleVector; BirdToThrow.transform.position = maxPosition; } else { BirdToThrow.transform.position = location; } float distance = Vector3.Distance(SlingshotMiddleVector, BirdToThrow.transform.position); //display projected trajectory based on the distance DisplayTrajectoryLineRenderer2(distance); } else//user has removed the tap { SetTrajectoryLineRenderesActive(false); //throw the bird!!! TimeSinceThrown = Time.time; float distance = Vector3.Distance(SlingshotMiddleVector, BirdToThrow.transform.position); if (distance > 1) { SetSlingshotLineRenderersActive(false); slingshotState = SlingshotState.BirdFlying; ThrowBird(distance); } else//not pulled long enough, so reinitiate it { //distance/10 was found with trial and error :) //animate the bird to the wait position BirdToThrow.transform.positionTo(distance / 10, //duration BirdWaitPosition.transform.position). //final position setOnCompleteHandler((x) => { x.complete(); x.destroy(); InitializeBird(); }); } } break; case SlingshotState.BirdFlying: break; default: break; } }
void Start() { slingshotState = SlingshotState.Idle; }
void Update() { switch (slingshotState) { case SlingshotState.Idle: if (Input.GetMouseButtonDown(0)) { Vector2 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (StartLaunchArea.OverlapPoint(worldPos)) { currentBall = GameObject.Instantiate(Ball); currentBall.transform.rotation = Launchbegin.transform.rotation; currentBall.SetActive(true); slingshotState = SlingshotState.UserPulling; } Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Ball.GetComponent <CircleCollider2D>() == Physics2D.OverlapPoint(location)) { slingshotState = SlingshotState.UserPulling; } } break; case SlingshotState.UserPulling: if (Input.GetMouseButton(0)) { Vector3 location = Camera.main.ScreenToWorldPoint(Input.mousePosition); location.z = 0; if (Vector3.Distance(location, Launchbegin.transform.position) > 2f) { var maxPosition = (location - Launchbegin.transform.position).normalized * 2f + Launchbegin.transform.position; currentBall.transform.position = maxPosition; } else { currentBall.transform.position = location; } float distance = Vector3.Distance(Launchbegin.transform.position, currentBall.transform.position); if (BadWindOnTrajectory) { distance = distance - wind; } DisplayTrajectoryLineRenderer2(distance); } else { currentBall.transform.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic; SetTrajectoryLineRenderesActive(false); float distance = Vector3.Distance(Launchbegin.transform.position, currentBall.transform.position); distance = distance - wind; slingshotState = SlingshotState.BirdFlying; Throw(distance); } break; case SlingshotState.BirdFlying: if (addforceWind) { currentBall.GetComponent <Rigidbody2D>().AddForce(new Vector2(-wind, 0)); } else { slingshotState = SlingshotState.Idle; } if (currentBall.GetComponent <Ball>().swotch) { slingshotState = SlingshotState.Idle; } break; default: break; } }