private void Update() { bool ret = false; if (bot == false) { try { CustomControls.GetButton(joystick, button1); joystick.Poll(); FindObjectOfType <ControllerDisconnect>().Reconnect(playerNumber); } catch { FindObjectOfType <ControllerDisconnect>().Disconnect(playerNumber); joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; button1 = FindObjectOfType <PlayerData>().button1[playerNumber]; button2 = FindObjectOfType <PlayerData>().button2[playerNumber]; ret = true; } } if (ret) { return; } if (infection == true) { team.transform.localEulerAngles = -transform.eulerAngles; } if (Time.timeScale != 0) { UpdateMe(); } }
public void Shoot() { if (CustomControls.GetButton(joystick, button1) && ableToShoot) { ableToShoot = false; GameObject cloneBullet = Instantiate(bullet) as GameObject; cloneBullet.transform.position = bulletPosition.transform.position; if (team == 0) { cloneBullet.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, bulletSpeed); } else if (team == 1) { cloneBullet.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, -bulletSpeed); } cloneBullet.GetComponent <SpaceShooter_Bullet>().GetDamageInfo(bulletDamage); cloneBullet.GetComponent <SpaceShooter_Bullet>().GetTeamInfo(team); cloneBullet.GetComponent <SpaceShooter_Bullet>().player = gameObject; if (tripleShot) { GameObject cloneBullet2 = Instantiate(bullet) as GameObject; cloneBullet2.transform.position = bulletPosition.transform.position; if (team == 0) { cloneBullet2.GetComponent <Rigidbody2D>().velocity = new Vector2(2f, bulletSpeed); } else if (team == 1) { cloneBullet2.GetComponent <Rigidbody2D>().velocity = new Vector2(2f, -bulletSpeed); } cloneBullet2.GetComponent <SpaceShooter_Bullet>().GetDamageInfo(bulletDamage); cloneBullet2.GetComponent <SpaceShooter_Bullet>().GetTeamInfo(team); cloneBullet2.GetComponent <SpaceShooter_Bullet>().player = gameObject; GameObject cloneBullet3 = Instantiate(bullet) as GameObject; cloneBullet3.transform.position = bulletPosition.transform.position; if (team == 0) { cloneBullet3.GetComponent <Rigidbody2D>().velocity = new Vector2(-2f, bulletSpeed); } else if (team == 1) { cloneBullet3.GetComponent <Rigidbody2D>().velocity = new Vector2(-2f, -bulletSpeed); } cloneBullet3.GetComponent <SpaceShooter_Bullet>().GetDamageInfo(bulletDamage); cloneBullet3.GetComponent <SpaceShooter_Bullet>().GetTeamInfo(team); cloneBullet3.GetComponent <SpaceShooter_Bullet>().player = gameObject; } shoot.Play(); Invoke("AbleToShoot", attackSpeed); } }
private void Movement() { if (!bot) { if (keyboard) { if (CustomControls.GetButton(joystick, stanga)) { GetComponent <Rigidbody2D>().velocity = new Vector2(-shipSpeed, GetComponent <Rigidbody2D>().velocity.y); } else if (CustomControls.GetButton(joystick, dreapta)) { GetComponent <Rigidbody2D>().velocity = new Vector2(shipSpeed, GetComponent <Rigidbody2D>().velocity.y); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); } if (CustomControls.GetButton(joystick, sus)) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, shipSpeed); } else if (CustomControls.GetButton(joystick, jos)) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, -shipSpeed); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, 0); } } else if ((CustomControls.GetAxis(joystick).Yaxis > 40000 || CustomControls.GetAxis(joystick).Yaxis < 20000 || CustomControls.GetAxis(joystick).Xaxis > 40000 || CustomControls.GetAxis(joystick).Xaxis < 20000)) { GetComponent <Rigidbody2D>().velocity = new Vector2(shipSpeed * (CustomControls.GetAxis(joystick).Xaxis - 32767) / 32767, -shipSpeed * (CustomControls.GetAxis(joystick).Yaxis - 32767) / 32767); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); } } }
public void Ultimate() { if (CustomControls.GetButton(joystick, button2) && !usedUltimate) { if (!laserult) { GameObject cloneBullet = Instantiate(ultimateBullet) as GameObject; cloneBullet.transform.position = bulletPosition.transform.position; if (team == 0) { cloneBullet.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, ultimateSpeed); } else if (team == 1) { cloneBullet.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, -ultimateSpeed); } cloneBullet.GetComponent <SpaceShooter_Bullet>().GetDamageInfo(ultimateBulletDamage); cloneBullet.GetComponent <SpaceShooter_Bullet>().GetTeamInfo(team); cloneBullet.GetComponent <SpaceShooter_Bullet>().player = gameObject; ultimate.Play(); usedUltimate = true; } else { GameObject ult = Instantiate(laserUlt); ult.GetComponent <SpaceShooter_LaserUltimate>().team = team; ult.transform.position = laserUltPos.transform.position; ult.GetComponent <SpaceShooter_LaserUltimate>().active = true; tutorialAbleToMove = false; GetComponent <Rigidbody2D>().velocity = Vector2.zero; laserult = false; usedUltimate = true; Invoke("StartMoving", 2.5f); } } }
void Update() { if (FindObjectOfType <PlayerData>() != null) { if (joystick != null) { bool ret = false; if (bot == false) { try { joystick.Poll(); } catch { joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; try { joystick.Poll(); } catch { FindObjectOfType <PlayerData>().pendingControllers[playerNumber] = true; } button1 = FindObjectOfType <PlayerData>().button1[playerNumber]; button2 = FindObjectOfType <PlayerData>().button2[playerNumber]; ret = true; color1Index = 0; color2Index = 0; color1.color = colors[0]; color2.color = colors[0]; FindObjectOfType <PlayerData>().color1[playerNumber] = color1.color; FindObjectOfType <PlayerData>().color2[playerNumber] = color2.color; UI.SetActive(false); joined = false; botObj.SetActive(true); FindObjectOfType <PlayerData>().players.Remove(playerNumber); return; } } if (ret) { return; } } else { if (FindObjectOfType <PlayerData>().controllers[playerNumber] != null) { joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; try { joystick.Poll(); } catch { FindObjectOfType <PlayerData>().pendingControllers[playerNumber] = true; } button1 = FindObjectOfType <PlayerData>().button1[playerNumber]; button2 = FindObjectOfType <PlayerData>().button2[playerNumber]; } } } timeTillScene += Time.deltaTime; if (joystick != null) { if (CustomControls.GetButton(joystick, button1)) { Action1(); } else { CancelAction1(); } if (CustomControls.GetButton(joystick, button2)) { Action2(); } else { CancelAction2(); } if (keyboard) { if (CustomControls.GetButton(joystick, dreapta)) { if (axis == false) { axis = true; if (opposite == false) { SelectDreapta(); } else { SelectStanga(); } } } else if (CustomControls.GetButton(joystick, stanga)) { if (axis == false) { axis = true; if (opposite == false) { SelectStanga(); } else { SelectDreapta(); } } } else { axis = false; } } else { if (CustomControls.GetAxis(joystick).Xaxis > 40000) { if (axis == false) { axis = true; if (opposite == false) { SelectDreapta(); } else { SelectStanga(); } } } else if (CustomControls.GetAxis(joystick).Xaxis < 20000) { if (axis == false) { axis = true; if (opposite == false) { SelectStanga(); } else { SelectDreapta(); } } } else { axis = false; } } } }
void Update() { if (Time.timeScale != 0) { teamColor.transform.localEulerAngles = -transform.eulerAngles; if (ableToMove && tutorialAbleToMove) { if (grounded == false) { if (GetComponent <Rigidbody2D>().velocity.y > 1) { GetComponent <Animator>().Play("jumpBomberman"); playindAirAnim = true; playingAnim = false; } else if (GetComponent <Rigidbody2D>().velocity.y < -1) { GetComponent <Animator>().Play("fallBomberman"); playindAirAnim = true; playingAnim = false; } else { playindAirAnim = false; } } else { playindAirAnim = false; } if (keyboard) { if (CustomControls.GetButton(joystick, stanga)) { GetComponent <Rigidbody2D>().velocity = new Vector2(-speed, GetComponent <Rigidbody2D>().velocity.y); transform.eulerAngles = new Vector3(0, 180, 0); if (playingAnim == false && playindAirAnim == false) { GetComponent <Animator>().Play("runBomberman"); playingAnim = true; } } else if (CustomControls.GetButton(joystick, dreapta)) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed, GetComponent <Rigidbody2D>().velocity.y); transform.eulerAngles = new Vector3(0, 0, 0); if (playingAnim == false && playindAirAnim == false) { GetComponent <Animator>().Play("runBomberman"); playingAnim = true; } } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); if (playindAirAnim == false) { playingAnim = false; GetComponent <Animator>().Play("idle"); } } } else { if (CustomControls.GetAxis(joystick).Xaxis < 20000) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed * (CustomControls.GetAxis(joystick).Xaxis - 32767) / 32767, GetComponent <Rigidbody2D>().velocity.y); transform.eulerAngles = new Vector3(0, 180, 0); if (playingAnim == false && playindAirAnim == false) { GetComponent <Animator>().Play("runBomberman"); playingAnim = true; } } else if (CustomControls.GetAxis(joystick).Xaxis > 40000) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed * (CustomControls.GetAxis(joystick).Xaxis - 32767) / 32767, GetComponent <Rigidbody2D>().velocity.y); transform.eulerAngles = new Vector3(0, 0, 0); if (playingAnim == false && playindAirAnim == false) { GetComponent <Animator>().Play("runBomberman"); playingAnim = true; } } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); if (playindAirAnim == false) { playingAnim = false; GetComponent <Animator>().Play("idle"); } } } if (CustomControls.GetButton(joystick, button1)) { if (grounded == true) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, jumpHeight); if (allowSound == true) { AudioSource.PlayClipAtPoint(jump, Camera.main.transform.position); allowSound = false; Invoke("AllowSound", 0.25f); } } } if (CustomControls.GetButton(joystick, button2)) { if (allowBomb) { GameObject bomba = Instantiate(bomb); bomba.transform.position = transform.position; bomba.GetComponent <Bombermen_bomb>().team = team; bomba.GetComponent <Bombermen_bomb>().parent = gameObject; foreach (Bombermen_player player in FindObjectsOfType <Bombermen_player>()) { Physics2D.IgnoreCollision(bomba.GetComponent <CircleCollider2D>(), player.GetComponent <BoxCollider2D>()); } allowBomb = false; Invoke("AllowBomb", 2.5f); } } } } }
// Update is called once per frame void Update() { bool ret = false; if (bot == false) { try { CustomControls.GetButton(joystick, button1); joystick.Poll(); FindObjectOfType <ControllerDisconnect>().Reconnect(playerNumber); } catch { FindObjectOfType <ControllerDisconnect>().Disconnect(playerNumber); joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; button1 = FindObjectOfType <PlayerData>().button1[playerNumber]; button2 = FindObjectOfType <PlayerData>().button2[playerNumber]; ret = true; } } if (ret) { return; } if (bot == false) { delta += Time.deltaTime; if (delta >= 1) { delta = 0; try { joystick.Poll(); } catch { joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; button1 = PlayerPrefs.GetInt(joystick.Information.ProductName + "1", 0); button2 = PlayerPrefs.GetInt(joystick.Information.ProductName + "2", 2); if ((joystick.Information.Type == SharpDX.DirectInput.DeviceType.Keyboard) == false) { keyboard = false; } } } } if (Time.timeScale != 0) { if (teamColor != null) { teamColor.transform.localEulerAngles = -transform.eulerAngles; } if (!bot) { if (dashAnim == false && tutorialAbleToMove) { if (keyboard) { if (CustomControls.GetButton(joystick, stanga)) { GetComponent <Rigidbody2D>().velocity = new Vector2(-speed, GetComponent <Rigidbody2D>().velocity.y); } else if (CustomControls.GetButton(joystick, dreapta)) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed, GetComponent <Rigidbody2D>().velocity.y); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); } if (CustomControls.GetButton(joystick, sus)) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, speed); } else if (CustomControls.GetButton(joystick, jos)) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, -speed); } else if ((CustomControls.GetAxis(joystick).Yaxis > 40000 || CustomControls.GetAxis(joystick).Yaxis < 20000 || CustomControls.GetAxis(joystick).Xaxis > 40000 || CustomControls.GetAxis(joystick).Xaxis < 20000)) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, 0); } } else if ((CustomControls.GetAxis(joystick).Yaxis > 40000 || CustomControls.GetAxis(joystick).Yaxis < 20000 || CustomControls.GetAxis(joystick).Xaxis > 40000 || CustomControls.GetAxis(joystick).Xaxis < 20000)) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed * (CustomControls.GetAxis(joystick).Xaxis - 32767) / 32767, -speed * (CustomControls.GetAxis(joystick).Yaxis - 32767) / 32767); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); } if (keyboard) { if ((CustomControls.GetButton(joystick, stanga) || CustomControls.GetButton(joystick, dreapta) || CustomControls.GetButton(joystick, jos) || CustomControls.GetButton(joystick, sus))) { float rotZ = transform.rotation.z; transform.rotation = Quaternion.LookRotation(GetComponent <Rigidbody2D>().velocity * 100, new Vector3(0, 0, 1)); transform.rotation = new Quaternion(0, 0, transform.rotation.z, transform.rotation.w); if (GetComponent <Rigidbody2D>().velocity == new Vector2(0, 0)) { transform.rotation = new Quaternion(0, 0, rotZ, transform.rotation.w); } } } else { if ((CustomControls.GetAxis(joystick).Yaxis > 40000 || CustomControls.GetAxis(joystick).Yaxis < 20000 || CustomControls.GetAxis(joystick).Xaxis > 40000 || CustomControls.GetAxis(joystick).Xaxis < 20000)) { float rotZ = transform.rotation.z; transform.rotation = Quaternion.LookRotation(GetComponent <Rigidbody2D>().velocity * 100, new Vector3(0, 0, 1)); transform.rotation = new Quaternion(0, 0, transform.rotation.z, transform.rotation.w); if (GetComponent <Rigidbody2D>().velocity == new Vector2(0, 0)) { transform.rotation = new Quaternion(0, 0, rotZ, transform.rotation.w); } } } if (CustomControls.GetButton(joystick, button1)) { if (trap == true) { if (usedTrap == false) { GameObject trapClone = Instantiate(trapObj); trapClone.transform.position = transform.position; AudioSource.PlayClipAtPoint(beartrapsetup, Camera.main.transform.position); usedTrap = true; } } else { GetComponent <Rigidbody2D>().velocity = -transform.up * dashSpeed; dashAnim = true; AudioSource.PlayClipAtPoint(dash, Camera.main.transform.position); Invoke("StopDash", 0.25f); } } else { lockedRot = false; } if (CustomControls.GetButton(joystick, button2) && canAttack) { if (bulletPos.GetComponent <ZombieSurvival_wallDetect>().wall == null) { GameObject blt = Instantiate(bullet); blt.transform.position = bulletPos.transform.position; blt.GetComponent <ZombieSurvival_bullet>().damage = bltDmg; blt.GetComponent <ZombieSurvival_bullet>().parent = gameObject; blt.transform.rotation = transform.rotation; blt.GetComponent <Rigidbody2D>().velocity = -transform.up * bltSpd; } GetComponent <AudioSource>().Play(); canAttack = false; Invoke("CanAttack", atkSpd); } } } } }
public void Update() { bool ret = false; if (bot == false) { try { CustomControls.GetButton(joystick, button1); joystick.Poll(); FindObjectOfType <ControllerDisconnect>().Reconnect(playerNumber); } catch { FindObjectOfType <ControllerDisconnect>().Disconnect(playerNumber); joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; button1 = FindObjectOfType <PlayerData>().button1[playerNumber]; button2 = FindObjectOfType <PlayerData>().button2[playerNumber]; ret = true; } } if (ret) { return; } if (Time.timeScale != 0) { if (!bot) { if (tutorialAbleToMove) { Movement(); Shoot(); Ultimate(); } } else if (tutorialAbleToMove) { timeBetweenStyles += Time.deltaTime; if (difficulty == "easy") { if (botShoot) { if (UnityEngine.Random.Range(1, 100000) % 20 == 0) { GetComponent <SpaceShooter_Player>().BotShoot(); } } } else if (difficulty == "normal") { if (botShoot) { if (UnityEngine.Random.Range(1, 100000) % 5 == 0) { GetComponent <SpaceShooter_Player>().BotShoot(); } } } else { GetComponent <SpaceShooter_Player>().BotShoot(); } if (!isTrained) { if (botPlayStyle == "aggresive") { if (currentTarget == null) { float minDistance = 9999; GameObject currentPlayer = null; players = FindObjectsOfType <SpaceShooter_Player>(); for (int i = 0; i < players.Length; i++) { if (players[i] != null) { if (Vector2.Distance(players[i].transform.position, transform.position) < minDistance && players[i] != GetComponent <SpaceShooter_Player>() && players[i].team != GetComponent <SpaceShooter_Player>().team) { minDistance = Vector2.Distance(players[i].transform.position, transform.position); currentPlayer = players[i].gameObject; } } } currentTarget = currentPlayer; } if (timeBetweenStyles >= timeTillAggro && difficulty != "easy") { timeBetweenStyles = 0; botPlayStyle = "defensive"; currentTarget = null; } if (currentTarget != null) { if (difficulty != "easy") { transform.position = Vector2.MoveTowards(transform.position, new Vector2(currentTarget.transform.position.x, transform.position.y), Time.deltaTime * shipSpeed / 4 * 3); } else { transform.position = Vector2.MoveTowards(transform.position, new Vector2(currentTarget.transform.position.x, transform.position.y), Time.deltaTime * shipSpeed / 2); } } } else { if (timeBetweenStyles >= timeTillDef) { timeBetweenStyles = 0; botPlayStyle = "aggresive"; } if (target != null) { Vector3 newPos = Vector2.MoveTowards(transform.position, new Vector2(target.transform.position.x, transform.position.y), Time.deltaTime * shipSpeed / 4 * 3); transform.position = transform.position + (transform.position - newPos); if (newPos.x == transform.position.x) { newPos = Vector2.MoveTowards(transform.position, new Vector2(target.transform.position.x + UnityEngine.Random.Range(0.1f, -0.1f), transform.position.y), Time.deltaTime * shipSpeed / 4 * 3); transform.position = transform.position + (transform.position - newPos); } } } } transform.position = new Vector3(transform.position.x, transform.position.y, 0); } } teamColor.transform.localEulerAngles = -transform.eulerAngles; }
// Update is called once per frame void Update() { bool ret = false; if (bot == false) { try { CustomControls.GetButton(joystick, button1); joystick.Poll(); FindObjectOfType <ControllerDisconnect>().Reconnect(playerNumber); } catch { FindObjectOfType <ControllerDisconnect>().Disconnect(playerNumber); joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; button1 = FindObjectOfType <PlayerData>().button1[playerNumber]; button2 = FindObjectOfType <PlayerData>().button2[playerNumber]; ret = true; } } if (ret) { return; } if (bot == false) { delta += Time.deltaTime; if (delta >= 1) { delta = 0; try { joystick.Poll(); } catch { joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; button1 = PlayerPrefs.GetInt(joystick.Information.ProductName + "1", 0); button2 = PlayerPrefs.GetInt(joystick.Information.ProductName + "2", 2); if ((joystick.Information.Type == SharpDX.DirectInput.DeviceType.Keyboard) == false) { keyboard = false; } } } } if (Vel0) { GetComponent <Rigidbody2D>().velocity = Vector2.zero; } if (Time.timeScale != 0) { time += Time.deltaTime; teamColor.transform.localEulerAngles = -transform.eulerAngles; if (!bot) { if (ableToMove && tutorialAbleToMove) { oldScale = GetComponent <Rigidbody2D>().gravityScale; if (grounded == false) { if (GetComponent <Rigidbody2D>().gravityScale > 0) { if (GetComponent <Rigidbody2D>().velocity.y > 1) { GetComponent <Animator>().Play("jump"); playingMidAirAnim = true; playingAnim = false; } else if (GetComponent <Rigidbody2D>().velocity.y < -1) { GetComponent <Animator>().Play("fall"); playingMidAirAnim = true; playingAnim = false; } else { playingMidAirAnim = false; } } else { if (GetComponent <Rigidbody2D>().velocity.y < -1) { GetComponent <Animator>().Play("jump"); playingMidAirAnim = true; playingAnim = false; } else if (GetComponent <Rigidbody2D>().velocity.y > 1) { GetComponent <Animator>().Play("fall"); playingMidAirAnim = true; playingAnim = false; } else { playingMidAirAnim = false; } } } else { playingMidAirAnim = false; } if (keyboard) { if (CustomControls.GetButton(joystick, stanga) && moveLeft) { GetComponent <Rigidbody2D>().velocity = new Vector2(-speed * speedAmplifier, GetComponent <Rigidbody2D>().velocity.y); if (playingAnim == false && playingMidAirAnim == false) { playingAnim = true; GetComponent <Animator>().Play("run"); } } else if (CustomControls.GetButton(joystick, dreapta) && moveRight) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed * speedAmplifier, GetComponent <Rigidbody2D>().velocity.y); if (playingAnim == false && playingMidAirAnim == false) { playingAnim = true; GetComponent <Animator>().Play("run"); } } else { if (!freezing || !grounded) { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); } if (playingMidAirAnim == false) { playingAnim = false; GetComponent <Animator>().Play("idle"); } } } else { if (CustomControls.GetAxis(joystick).Xaxis < 20000 && moveLeft) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed * speedAmplifier * (CustomControls.GetAxis(joystick).Xaxis - 32767) / 32767, GetComponent <Rigidbody2D>().velocity.y); if (playingAnim == false && playingMidAirAnim == false) { playingAnim = true; GetComponent <Animator>().Play("run"); } } else if (CustomControls.GetAxis(joystick).Xaxis > 40000 && moveRight) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed * speedAmplifier * (CustomControls.GetAxis(joystick).Xaxis - 32767) / 32767, GetComponent <Rigidbody2D>().velocity.y); if (playingAnim == false && playingMidAirAnim == false) { playingAnim = true; GetComponent <Animator>().Play("run"); } } else { if (!freezing || !grounded) { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); } if (playingMidAirAnim == false) { playingAnim = false; GetComponent <Animator>().Play("idle"); } } } if (CustomControls.GetButton(joystick, button1) && grounded) { if (GetComponent <Rigidbody2D>().gravityScale < 0) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, -jumpHeight * jumpHeightAmplifier); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, jumpHeight * jumpHeightAmplifier); } jump.Play(); } if (CustomControls.GetButton(joystick, button2) && action2Type != 0) { if (action2Type == 1) { if (GetComponent <Rigidbody2D>().gravityScale < 0) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, -jumpHeight * jumpHeightAmplifier); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, jumpHeight * jumpHeightAmplifier); } action2Type = 0; jump.Play(); } else if (action2Type == 2) { GameObject cloneMine = Instantiate(mine); cloneMine.transform.position = transform.position; cloneMine.GetComponent <ParkourMasters_Mine>().player = gameObject; cloneMine.GetComponent <Rigidbody2D>().gravityScale = oldScale; cloneMine.transform.rotation = transform.rotation; cloneMine.transform.localScale = new Vector3(mineSize, mineSize, 1); Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), cloneMine.GetComponent <PolygonCollider2D>()); action2Type = 0; } else if (action2Type == 3) { GetComponent <Rigidbody2D>().velocity = new Vector2(dash, 0f); oldScale = GetComponent <Rigidbody2D>().gravityScale; GetComponent <Rigidbody2D>().gravityScale = 0; ableToMove = false; action2Type = 0; Invoke("StopDashing", 0.5f); } } } } else if (tutorialAbleToMove) { if (waypointIndex < waypoints.Count) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(waypoints[waypointIndex].transform.position.x, transform.position.y), speed * speedAmplifier * Time.deltaTime); } if (GetComponent <Rigidbody2D>().velocity.y > 1) { GetComponent <Animator>().Play("jump"); } else if (GetComponent <Rigidbody2D>().velocity.y < -1) { GetComponent <Animator>().Play("fall"); } else { GetComponent <Animator>().Play("run"); } if (waypointIndex < waypoints.Count) { if (waypoints[waypointIndex].transform.position.y - transform.position.y > 0.25f && GetComponent <Rigidbody2D>().gravityScale == 1) { if (grounded) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, jumpHeight * jumpHeightAmplifier); jump.Play(); } } else if (waypoints[waypointIndex].transform.position.y - transform.position.y < -0.25f && GetComponent <Rigidbody2D>().gravityScale == -1) { if (grounded) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, -jumpHeight * jumpHeightAmplifier); jump.Play(); } } if (Vector2.Distance(transform.position, waypoints[waypointIndex].transform.position) < 0.5f) { waypointIndex++; } } } } }
// Update is called once per frame public void UpdateMe() { if (trapped && bot) { GetComponent <AIPath>().enabled = false; } else if (trapped == false && bot == true) { GetComponent <AIPath>().enabled = true; } if (bot) { if (target != null) { } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); ZombieSurvival_player[] players = FindObjectsOfType <ZombieSurvival_player>(); if (players.Length != 0) { target = players[Random.Range(0, 10000000) % players.Length].gameObject; GetComponent <AIDestinationSetter>().target = target.transform; } } } else { delta += Time.deltaTime; if (delta >= 1) { delta = 0; try { joystick.Poll(); } catch { joystick = FindObjectOfType <PlayerData>().controllers[playerNumber]; button1 = PlayerPrefs.GetInt(joystick.Information.ProductName + "1", 0); button2 = PlayerPrefs.GetInt(joystick.Information.ProductName + "2", 2); if ((joystick.Information.Type == SharpDX.DirectInput.DeviceType.Keyboard) == false) { keyboard = false; } } } if (trapped == false) { if (keyboard) { if (CustomControls.GetButton(joystick, stanga)) { GetComponent <Rigidbody2D>().velocity = new Vector2(-speed, GetComponent <Rigidbody2D>().velocity.y); } else if (CustomControls.GetButton(joystick, dreapta)) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed, GetComponent <Rigidbody2D>().velocity.y); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); } if (CustomControls.GetButton(joystick, sus)) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, speed); } else if (CustomControls.GetButton(joystick, jos)) { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, -speed); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, 0); } } else if ((CustomControls.GetAxis(joystick).Yaxis > 40000 || CustomControls.GetAxis(joystick).Yaxis < 20000 || CustomControls.GetAxis(joystick).Xaxis > 40000 || CustomControls.GetAxis(joystick).Xaxis < 20000)) { GetComponent <Rigidbody2D>().velocity = new Vector2(speed * (CustomControls.GetAxis(joystick).Xaxis - 32767) / 32767, -speed * (CustomControls.GetAxis(joystick).Yaxis - 32767) / 32767); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); } } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); } if (keyboard) { if ((CustomControls.GetButton(joystick, stanga) || CustomControls.GetButton(joystick, dreapta) || CustomControls.GetButton(joystick, jos) || CustomControls.GetButton(joystick, sus))) { float rotZ = transform.rotation.z; transform.rotation = Quaternion.LookRotation(GetComponent <Rigidbody2D>().velocity * 100, new Vector3(0, 0, 1)); transform.rotation = new Quaternion(0, 0, transform.rotation.z, transform.rotation.w); if (GetComponent <Rigidbody2D>().velocity == new Vector2(0, 0)) { transform.rotation = new Quaternion(0, 0, rotZ, transform.rotation.w); } } } else { if ((CustomControls.GetAxis(joystick).Yaxis > 40000 || CustomControls.GetAxis(joystick).Yaxis < 20000 || CustomControls.GetAxis(joystick).Xaxis > 40000 || CustomControls.GetAxis(joystick).Xaxis < 20000)) { float rotZ = transform.rotation.z; transform.rotation = Quaternion.LookRotation(GetComponent <Rigidbody2D>().velocity * 100, new Vector3(0, 0, 1)); transform.rotation = new Quaternion(0, 0, transform.rotation.z, transform.rotation.w); if (GetComponent <Rigidbody2D>().velocity == new Vector2(0, 0)) { transform.rotation = new Quaternion(0, 0, rotZ, transform.rotation.w); } } } if (CustomControls.GetButton(joystick, button1) && bombThrown == false) { bombThrown = true; GameObject bombClone = Instantiate(bomb); bombClone.GetComponent <ZombieInfection_bomb>().active = true; bombClone.transform.position = transform.position; bombClone.transform.rotation = transform.rotation; bombClone.GetComponent <Rigidbody2D>().velocity = -transform.up * bombForce; } if (CustomControls.GetButton(joystick, button2) && attacking == false) { attacking = true; GetComponent <CircleCollider2D>().enabled = true; } else { if (CustomControls.GetButton(joystick, button2) == true && attacking == true) { GetComponent <CircleCollider2D>().enabled = false; } if (CustomControls.GetButton(joystick, button2) == false && attacking == true) { attacking = false; } } } }