void Awake() { //This needs to go first, or we get problems myAnim = GetComponent <Animator>(); //If you don't have a controller plugged in, the game is UNPLAYABLE player = InputManager.Devices[playerNumber]; mybody = GetComponent <Rigidbody2D>(); particles = GetComponentsInChildren <ParticleSystem>(); //gets the game managers script myGM = GameObject.Find("GameManager").GetComponent <Script_GameManager>(); //Gets dash move from the game object myDashMove = gameObject.GetComponent <Script_DashMove>(); //Gets dash particles from the game object myDashParticles = gameObject.transform.Find("Dash Particles").GetComponent <ParticleSystem>(); //Gets dash particles from the game object myTaggedParticles = gameObject.transform.Find("Tagged Particles").GetComponent <ParticleSystem>(); //finds child dash particles with name "Dash Particles" audioManager = GameObject.FindObjectOfType <AudioManager>(); }
public void Move(float horizontalInput, Rigidbody2D mybody, Script_DashMove myDashMove) { //Code for keyboard controls if (Input.GetKey(KeyCode.A)) { horizontalInput = -1f; } if (Input.GetKey(KeyCode.D)) { horizontalInput = 1f; } // separates movement into discrete speeds (crawl, walk, run) if (horizontalInput > 0 && horizontalInput <= 0.3f) { horizontalInput = 0.3f; } else if (horizontalInput > 0.3f && horizontalInput <= 0.9f) { horizontalInput = 0.5f; } else if (horizontalInput > 0.8f && horizontalInput <= 1) { horizontalInput = 1; } if (horizontalInput < 0 && horizontalInput >= -0.3f) { horizontalInput = -0.3f; } else if (horizontalInput < -0.3f && horizontalInput >= -0.9f) { horizontalInput = -0.5f; } else if (horizontalInput < -0.8f && horizontalInput > -1) { horizontalInput = -1; } //this is necessary so this code doesn't overwrite the dash velocity //Simply checks if we are dashing or not if (myDashMove.direction == 0) { mybody.velocity = new Vector2(horizontalInput * speed, mybody.velocity.y); } }
public void Dash(InputControl xControl, Script_DashMove myDashMove) { //camera shake function CameraShaker.Instance.ShakeOnce(5f, 3f, 0f, .5f); InputControl aimX = player.GetControl(InputControlType.LeftStickX); InputControl aimY = player.GetControl(InputControlType.LeftStickY); float Y = aimY.Value; float X = aimX.Value; float YAbsVal = Mathf.Abs(Y); float XAbsVal = Mathf.Abs(X); if (X < 0 && XAbsVal > YAbsVal) { myDashMove.direction = 1; } else if (X > 0 && XAbsVal > YAbsVal) { myDashMove.direction = 2; } else if (Y > 0 && YAbsVal > XAbsVal) { myDashMove.direction = 3; } else if (Y < 0 && YAbsVal > XAbsVal) { myDashMove.direction = 4; } else if (xControl.Value == 0) { if (facingRight) { myDashMove.direction = 2; } if (!facingRight) { myDashMove.direction = 1; } } //Needs to go at end because this depends on the myDashMove.direction value StartCoroutine("dashFlash"); }