public void SetScriptsActive() { // For when we want to set everything as active GetComponent <PlayerController>().enabled = true; Weapon _weapon = GetComponentInChildren <Weapon>(); if (_weapon != null) { _weapon.enabled = true; } ArmRotation playerArmRotationScript = GetComponentInChildren <ArmRotation>(); if (playerArmRotationScript != null) { playerArmRotationScript.enabled = true; } foreach (GameObject door in doors) { door.GetComponentInChildren <Door>().enabled = true; } GetComponent <Rigidbody2D>().gravityScale = 1; Cursor.visible = false; }
//outdated GamePause... solved with timescale = 0.0f during pause void OnPauseGameToggle(bool active) { // handle what happens when the upgrade menu is toggled if (this == null) { return; } keysEnabled = !active; //Rigidbody2D rb = GetComponent<Rigidbody2D>(); //GetComponent<Platformer2DUserControl>().enabled = !active; /*if (active == true) * { * previousForce = rb.velocity; * rb.constraints = RigidbodyConstraints2D.FreezeAll; * CancelInvoke("RegenHealth"); * } * else if (active == false) * { * rb.constraints = RigidbodyConstraints2D.None | RigidbodyConstraints2D.FreezeRotation; * rb.velocity = previousForce; * InvokeRepeating("RegenHealth", 1f, 0.5f); * }*/ Weapon _weapon = GetComponentInChildren <Weapon>(); ArmRotation _armRotation = GetComponentInChildren <ArmRotation>(); if (_weapon != null) { _weapon.enabled = !active; } if (_armRotation != null) { _armRotation.enabled = !active; } }
void OnUpgradeMenuToggle(bool active) { //handle what happens, when upgrade menu is toggled GetComponent <Platformer2DUserControl>().enabled = !active; //GetComponent<SpriteRenderer>().enabled = !active; ArmRotation _armR = GetComponentInChildren <ArmRotation>(); if (_armR != null) { _armR.enabled = !active; } Weapon _weapon = GetComponentInChildren <Weapon>(); if (_weapon != null) { _weapon.enabled = !active; } if (active) { Time.timeScale = 0f; } else { Time.timeScale = 1f; } }
// Use this for initialization void Awake() { anim = GetComponent <Animator>(); rb2d = GetComponent <Rigidbody2D>(); Bdash = true; disparador = disparador.GetComponent <Disparo>(); offSet = brazo.GetComponent <ArmRotation>(); apareceVestido = false; gravedad = -3; Physics.gravity = new Vector2(0, gravedad); }
void Start() { alertStateTimer = alertStateTimerLength; mayBeAlertTimer = mayBeAlertTimerLength; arm = gameObject.transform.Find("EnemyArm"); enemySight = gameObject.transform.Find("Sight"); enemyHearing = gameObject.transform.Find("Hearing"); enemies = GameObject.FindGameObjectsWithTag("Enemy"); thisEnemyCollider = gameObject.GetComponent <CapsuleCollider2D>(); rooms = GameObject.FindGameObjectsWithTag("Room"); patrolPointContainer = GameObject.Find("PatrolPoints"); currentPatrolIndex = 0; currentPatrolPoint = enemyPatrolPoints[currentPatrolIndex]; stairwaysGoingUp = GameObject.FindGameObjectsWithTag("StairsUp"); stairwaysGoingDown = GameObject.FindGameObjectsWithTag("StairsDown"); currentState = startState; player = Player.instance; playerControllerScript = player.GetComponent <PlayerController>(); enemySightScript = enemySight.GetComponent <EnemySight>(); enemyHearingScript = enemyHearing.GetComponent <EnemyHearing>(); enemyScript = gameObject.GetComponent <Enemy>(); armRotationScript = arm.GetComponent <ArmRotation>(); anim = GetComponent <Animator>(); enemyLocalScale = transform.localScale; rb = GetComponent <Rigidbody2D>(); if (facingRight == false) { enemyLocalScale.x *= -1; transform.localScale = enemyLocalScale; armRotationScript.enemyRotationOffset = 180; facingRight = false; } playerWeapons = GameObject.Find("WeaponPool").transform.GetComponentsInChildren <BoxCollider2D>(); foreach (BoxCollider2D playerWeaponCollider in playerWeapons) { Physics2D.IgnoreCollision(playerWeaponCollider, thisEnemyCollider); } }
private bool stopMoveButt; //check to see if player is pressing the "stop and stand in place" button //public int jumpDelay = 200; //public IEnumerator jumpUp() //{ // yield return new WaitForSeconds(jumpDelay); //m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce)); //} private void Awake() { // Setting up references. m_GroundCheck = transform.Find("GroundCheck"); m_CeilingCheck = transform.Find("CeilingCheck"); m_Anim = GetComponent <Animator>(); m_Rigidbody2D = GetComponent <Rigidbody2D>(); playerGraphics = transform.Find("Graphics"); if (playerGraphics == null) { Debug.LogError("There is no graphics object as a child of the player"); } rotator = GetComponentInChildren <ArmRotation>(); }
void OnGamePauseToggle(bool active) { GetComponent <Platformer2DUserControl>().enabled = !active; Weapon _weapon = GetComponentInChildren <Weapon>(); if (_weapon != null) { _weapon.enabled = !active; } ArmRotation _armRotation = GetComponentInChildren <ArmRotation>(); if (_armRotation != null) { _armRotation.enabled = !active; } }
void Start() { player = Player.instance; patrolPoints = GameObject.FindGameObjectsWithTag("PatrolPoint"); foreach (GameObject patrolPoint in patrolPoints) { BoxCollider2D patrolPointCollider = patrolPoint.gameObject.GetComponent <BoxCollider2D>(); Physics2D.IgnoreCollision(player.GetComponent <CapsuleCollider2D>(), patrolPointCollider); } lights = GameObject.FindGameObjectsWithTag("Light"); foreach (GameObject light in lights) { Physics2D.IgnoreCollision(player.GetComponent <CapsuleCollider2D>(), light.GetComponent <BoxCollider2D>()); } arm = gameObject.transform.Find("Arm"); armRotationScript = arm.GetComponent <ArmRotation>(); playerSpriteRenderer = GetComponent <SpriteRenderer>(); playerAnim = GetComponent <Animator>(); rigidBody = GetComponent <Rigidbody2D>(); rigidBody.freezeRotation = true; childSpriteRenderer = GetComponentsInChildren <SpriteRenderer>(); playerLocation = transform.localScale; currentFloorLevel = 1; currentRoomNumber = 0; currentRoom = GameObject.Find("OutsideLeftCollider").transform; audioManager = AudioManager.instance; if (audioManager == null) { Debug.LogError("No audio manager found."); } }
// Use this for initialization void Start() { // Obtenim el component (del player) rb2d = GetComponent <Rigidbody2D>(); // Obtenim el component animador anim = GetComponent <Animator>(); spr = GetComponent <SpriteRenderer>(); //Arm arm = transform.Find("Arm").gameObject; rotation = arm.GetComponent <ArmRotation>(); goPistol = transform.Find("Arm/Pistol").gameObject; pistol = goPistol.GetComponent <Pistol>(); goPickaxe = transform.Find("Arm/Pickaxe").gameObject; pickaxe = goPickaxe.GetComponent <Pickaxe>(); goGrenadeThrower = transform.Find("Arm/GrenadeThrower").gameObject; grenadeThrower = goGrenadeThrower.GetComponent <GrenadeThrower>(); goPickaxe.SetActive(false); goGrenadeThrower.SetActive(false); heightToDead = -12; if (gameObject.tag == "team1") { teamRed = true; } else { teamBlue = true; } keyboard = true; flags = 0; }
void OnPauseMenuToggle(bool active) { // Handle what happens when the pause menu is toggled GetComponent <PlayerController>().enabled = !active; Weapon _weapon = GetComponentInChildren <Weapon>(); if (_weapon != null) { _weapon.enabled = !active; } ArmRotation playerArmRotationScript = GetComponentInChildren <ArmRotation>(); if (playerArmRotationScript != null) { playerArmRotationScript.enabled = !active; } foreach (GameObject door in doors) { door.GetComponentInChildren <Door>().enabled = !active; } }
// Torna a sortir el personatge al mateix lloc si sortim de l'escena. /* * void OnBecameInvisible() * { * transform.position = new Vector3(-1, 0, 0); * } */ public void setMovement(bool mov) { //Debug.Log (mov); this.movement = mov; //Enable rotation to player if (this.rotation == null || this.pistol == null) // ALERTA (más de lo mismo) { arm = transform.Find("Arm").gameObject; rotation = arm.GetComponent <ArmRotation>(); goPistol = transform.Find("Arm/Pistol").gameObject; pistol = goPistol.GetComponent <Pistol>(); goPickaxe = transform.Find("Arm/Pickaxe").gameObject; pickaxe = goPickaxe.GetComponent <Pickaxe>(); goGrenadeThrower = transform.Find("Arm/GrenadeThrower").gameObject; grenadeThrower = goGrenadeThrower.GetComponent <GrenadeThrower>(); } this.rotation.setEnabledRotation(movement); this.pistol.setEnabledShoot(movement); this.pickaxe.setEnabledShoot(movement); this.grenadeThrower.setEnabledShoot(movement); }
void Awake() { // Get all required components and objects player = GameObject.Find("Player").GetComponent<Player>(); PlayerCollider = GameObject.Find("Player").GetComponent<BoxCollider2D>(); FirePoint = transform.GetChild(0); weaponEffects = GetComponent<WeaponEffects> (); RandomizeFirerate = EnemyAimDelay; Arm = this.transform.parent.GetComponent<ArmRotation> (); audioSource = GameObject.Find ("AudioManager/EffectsAudio").GetComponent<AudioSource> (); if(FirePoint == null){ Debug.LogError ("No 'FirePoint' object found."); } if(weaponEffects == null) { Debug.LogError ("Script for weapon effects is missing!"); } if(WeaponFireSoundEffect == null){ Debug.LogError ("WeaponFireSoundEffect is missing!"); } }
// Update is called once per frame void Update() { windowWidth = Input.mousePosition.x - transform.position.x; // Rotate character playerPosX = (int)transform.position.x; GetComponent <HealthBar>().DistanceChange = playerPosX; Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 moveDir = (mousePos - transform.Find("CameraFollow").position); cameraFollowPosX = transform.Find("CameraFollow").position.x; if (differenceX > changeDirOffset && !facingRight) { Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; facingRight = true; ArmRotation.changeDir("Right"); Vector3 oldPos = transform.Find("Karakter_3").position; oldPos.x -= posChange; transform.Find("Karakter_3").position = oldPos; } else if (differenceX < -changeDirOffset && facingRight) { Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; facingRight = false; ArmRotation.changeDir("Left"); Vector3 oldPos = transform.Find("Karakter_3").position; oldPos.x += posChange; transform.Find("Karakter_3").position = oldPos; } // Movement weight = PlayerVariables.health; speed = (speedForce - ((speedForce - 1) * weight / 100)); if (Input.GetKey(KeyCode.A)) { GetComponent <Rigidbody2D>().velocity = new Vector2(-(speedForce - (4 * weight / 100)), GetComponent <Rigidbody2D>().velocity.y); isMoving = true; transform.Find("Karakter_3").GetComponent <Animator>().SetBool("isWalking", true); transform.Find("Karakter_2").GetComponent <Animator>().SetBool("isWalking", true); transform.Find("Karakter_1").GetComponent <Animator>().SetBool("isWalking", true); transform.Find("Karakter_0").GetComponent <Animator>().SetBool("isWalking", true); } else if (Input.GetKey(KeyCode.D)) { GetComponent <Rigidbody2D>().velocity = new Vector2(speedForce - (4 * weight / 100), GetComponent <Rigidbody2D>().velocity.y); isMoving = true; transform.Find("Karakter_3").GetComponent <Animator>().SetBool("isWalking", true); transform.Find("Karakter_2").GetComponent <Animator>().SetBool("isWalking", true); transform.Find("Karakter_1").GetComponent <Animator>().SetBool("isWalking", true); transform.Find("Karakter_0").GetComponent <Animator>().SetBool("isWalking", true); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); isMoving = false; transform.Find("Karakter_3").GetComponent <Animator>().SetBool("isWalking", false); transform.Find("Karakter_2").GetComponent <Animator>().SetBool("isWalking", false); transform.Find("Karakter_1").GetComponent <Animator>().SetBool("isWalking", false); transform.Find("Karakter_0").GetComponent <Animator>().SetBool("isWalking", false); } /* The old (commented) isGrounded were to slow to react so that double jumping could occure without enabling the timer, so it has now been updated to a more responsive version */ // isGrounded = Physics2D.Linecast(this.transform.position, new Vector2(transform.position.x, transform.position.y - length), ground);// OverlapCircle (transform.position, radius, ground); velocityY = GetComponent <Rigidbody2D>().velocity.y; isGrounded = velocityY <1e-8 && velocityY> -1e-8; /* * Jumping - Double jump every 5 seconds * Minor glitch where velocity.y is around 6-7*e-9 or something after double jump or while moving */ if (doubleJumpCDTimer > 0.0f) { doubleJumpCDTimer -= Time.deltaTime; } if (doubleJumpCDTimer < 0.0f) { doubleJumpCDTimer = 0.0f; } // Single jump if (Input.GetKeyDown(KeyCode.Space) && isGrounded) { GetComponent <Rigidbody2D>().AddForce(jumpVector, ForceMode2D.Force); } // Double jump if (Input.GetKeyDown(KeyCode.Space) && !isGrounded && doubleJumpCDTimer == 0.0f) { Debug.Log("DOUBLE JUMP"); doubleJumpCDTimer = doubleJumpCDDuration; GetComponent <Rigidbody2D>().AddForce(doubleJumpVector, ForceMode2D.Force); HealthBar.startDoubleJumpCD(doubleJumpCDDuration); } /* Sprint */ if (sprintCDTimer > 0.0f) { sprintCDTimer -= Time.deltaTime; } if (sprintCDTimer < 0.0f) { sprintCDTimer = 0.0f; } // sprint activate if (Input.GetKeyDown(KeyCode.LeftShift) && sprintCDTimer == 0.0f) { isSprinting = true; sprintTimer = sprintDuration; sprintCDTimer = sprintCDDuration; oldSpeed = speedForce; speedForce *= 1.5f; HealthBar.startSprintCD(sprintCDDuration); } if (isSprinting) { sprintTimer -= Time.deltaTime; if (sprintTimer < 0.0f) { isSprinting = false; speedForce = oldSpeed; } } // Shooting if (Input.GetKey(KeyCode.Mouse0)) { if (!shootOnCD) { source.PlayOneShot(magen, vol); StopCoroutine(Fire()); StartCoroutine(Fire()); } } // Food consumption if (Input.GetKeyDown(KeyCode.Mouse1)) { if (PlayerVariables.burgerCount > 0 && PlayerVariables.health != 100) { Debug.Log("Right Mouse Down " + PlayerVariables.burgerCount); HealthBar.eatBurger(); PlayerVariables.changeBurgerCount(-1); } } differenceX = moveDir.x; }
// Use this for initialization void Start() { rb2D = GetComponent <Rigidbody2D> (); inverseMoveTime = 1f / moveTime; armScript = playerArm.GetComponent <ArmRotation> (); }