// external function to check all switches public void CheckAllSwitches() { // for each switch, get their script and check their status foreach (GameObject obj in switchList) { SwitchScript ss = obj.GetComponent <SwitchScript>(); // if false, can return immediately since all switches need to be true if (ss.CheckSwitch() == false) { return; } } // if all switches are pressed, check to make sure players don't have keys yet GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { PlayerController p = player.GetComponent <PlayerController>(); if (p.checkKey()) { return; } } // if all conditions passed, spawn the keys SpawnKeys(); }
void OnTriggerEnter(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("CharacterBody") || other.gameObject.layer == LayerMask.NameToLayer("Character")) { SwitchScript s = GetComponentInParent <SwitchScript>(); if (s != null) { s.Activate(); } else { s = transform.parent.GetComponentInParent <SwitchScript>(); if (s != null) { s.Activate(); } else { Animator a = GetComponent <Animator>(); if (a != null) { a.SetTrigger("Trigger"); Root.Instance.m_Character.m_HasKey = true; } } } } }
private void SwitchHitHandler(GameObject switchObj, GameObject puck) { if (remainingHits > 0) { SwitchScript switchScript = switchObj.GetComponent <SwitchScript>(); remainingHits = switchScript.state ? remainingHits + 1 : remainingHits - 1; //objectiveText.text = string.Format(objectiveString, remainingHits, numSwitches); if (remainingHits <= 0) { //objectiveText.text = string.Format(completedString, numSwitches); if (EventList.AddRotatingText != null) { EventList.AddRotatingText(titleString, string.Format(completedString, numSwitches)); } string missionId = Constants.GetMissionId(missionName); if (missionId == null) { Debug.LogError("Could not retrieve mission Id for mission name: " + missionName); return; } if (EventList.MissionCompleted != null) { EventList.MissionCompleted(missionId); } } else if (EventList.AddRotatingText != null) { EventList.AddRotatingText(titleString, string.Format(objectiveString, remainingHits, numSwitches)); } } }
void OnTriggerEnter2D(Collider2D otherCollider) { SwitchScript switchs = otherCollider.gameObject.GetComponent <SwitchScript> (); if (switchs != null) { switchs.ChangeSwitch(); } }
void Start() { worldPos = new Vector3 (0, 0, 0); old_worldPos = new Vector3 (0, 0, 0); cursor = GameObject.Find ("cursor"); DrawFlag = false; //SWをSwitchに関連付け _switch = GameObject.Find("Switch"); SW = _switch.AddComponent<SwitchScript>(); }
private float doorRotated = 0f; //amount of degree the door has rotated // Use this for initialization void Start() { //Getting components from the switch switchObject = GameObject.FindGameObjectWithTag(name + "Switch"); switchScript = switchObject.GetComponent <SwitchScript>(); //Getting componets from the game controller gameControllerObject = GameObject.FindGameObjectWithTag("GameController"); gameController = gameControllerObject.GetComponent <GameController>(); //Calculating the movement variables of the door circumference = 2 * Mathf.PI * 1; rotationAmount = rotationSpeed * Time.deltaTime; moveAmount = (circumference / 360); }
public static SpeechTriggerControllerScript GenerateSpeechScript(GameObject target, Transform followTarget, string speakerName, string locStringID, AudioClip voice = null, bool freezePlayer = false, GameObject forceSpawnPedro = null) { SwitchScript switchScript = target.AddComponent <SwitchScript>(); switchScript.output = 1; SpeechTriggerScript speechTriggerScript = target.AddComponent <SpeechTriggerScript>(); if (freezePlayer) { speechTriggerScript.clickToContinue = true; speechTriggerScript.clickToContinueDontFreeze = false; } speechTriggerScript.followTransform = followTarget; speechTriggerScript.speakerName = speakerName; if (forceSpawnPedro != null) { speechTriggerScript.forceSpawnPedro = forceSpawnPedro.GetComponent <PedroScript>(); } string testString = ""; LocalizationManager.TryGetTranslation(speakerName, out testString); if (testString.ToLower().Contains("missing translation")) { MFPEditorUtils.CreateTranslation(speakerName, speakerName); } if (voice != null) { speechTriggerScript.voice = voice; } speechTriggerScript.locStringId = locStringID; SpeechTriggerControllerScript controllerScript = target.AddComponent <SpeechTriggerControllerScript>();; controllerScript.inputSwitch = new SwitchScript[0]; return(controllerScript); }
// external function to check all switches public void CheckAllSwitches() { // for each switch, get their script and check their status foreach (GameObject obj in mySwitches) { SwitchScript ss = obj.GetComponent <SwitchScript>(); // if false, can return immediately since all switches need to be true if (ss.CheckSwitch() == false) { return; } } // if all switches are pressed, open gate GateScript gs = gate.GetComponent <GateScript>(); gs.GateOpen(); }
public void WeaponCollide(Collider other) { if (m_NextState == this) { if (other.gameObject.layer == LayerMask.NameToLayer("Switch") || other.gameObject.layer == LayerMask.NameToLayer("Terrain")) { SwitchScript s = other.GetComponentInParent <SwitchScript>(); if (s != null) { s.HitSwitch(); } else { s = other.transform.parent.GetComponentInParent <SwitchScript>(); if (s != null) { s.HitSwitch(); } } } } }
// Update is called once per frame void Update() { // Check if crosshair is behind player if (transform.position.x < Camera.main.ScreenToWorldPoint(Input.mousePosition).x) { if (!isFacingRight) { flip(); isFacingRight = true; } } else { if (isFacingRight) { flip(); isFacingRight = false; } } // Check if animation is currently playing so player is invincible if (takingDamage == true) { invincibleTimer -= Time.deltaTime; } // If animation is not playing anymore if (invincibleTimer <= 0) { takingDamage = false; } // Delay on rolling so you can't keep rolling if (rollDelay > 0) { rollDelay -= Time.deltaTime; } // count down on roll timer and invisibility timer if (rollTimer >= 0) { rollTimer -= Time.deltaTime; // change sprite to something else //gameObject.GetComponent<SpriteRenderer>().sprite = rollSprite; } else { isRoll = false; rollTimer = rollTime; //change sprite back to original //gameObject.GetComponent<SpriteRenderer>().sprite = mainSprite; } checkCrouch(); // Check if interaction key is being pressed if (Input.GetKeyDown("f")) { // Check if touching a sign if (touchSign) { // Do something here GameObject sign = GameObject.FindGameObjectWithTag("IsTouching"); sign.transform.GetChild(0).gameObject.GetComponent <TextMeshPro>().SetText("This Is A Sign."); } // Check if door is open else if (touchDoor) { // Determine which door is which GameObject originDoor = GameObject.FindGameObjectWithTag("IsTouching"); DoorScript doorScript = originDoor.GetComponent <DoorScript>(); if (doorScript.isOpen) { GameObject destDoor = GameObject.FindGameObjectWithTag("TeleportDoor"); transform.position = destDoor.transform.position; pet.transform.position = destDoor.transform.position; AstarPath.active.Scan(); } } // Check if touching a switch else if (touchSwitch) { SwitchScript switchScript = GameObject.FindGameObjectWithTag("IsTouching").GetComponent <SwitchScript>(); // Change status of switch if (switchScript.isOn) { switchScript.isOn = false; } else { switchScript.isOn = true; } } // Check if touching wall switch else if (touchWallSwitch) { WallSwitchScript wsScript = GameObject.FindGameObjectWithTag("IsTouching").GetComponent <WallSwitchScript>(); if (wsScript.state) { wsScript.state = false; wsScript.OpenDoor(); animator.SetBool("isInteracting", true); } } else if (touchPuzzleSwitch) { PuzzleSwitchScript psScript = GameObject.FindGameObjectWithTag("IsTouching").GetComponent <PuzzleSwitchScript>(); if (psScript.state) { psScript.state = false; } else { psScript.state = true; } } } // Checks if the "d" key is being pressed if (Input.GetKey("d") && !isRoll) { // Changes the x-axis velocity of the player while retaining the y-axis velocity if (isCrouching) { rbody.velocity = new Vector3(moveSpeed / 2, rbody.velocity.y); } else { rbody.velocity = new Vector2(moveSpeed, rbody.velocity.y); } } // Checks if the "a" key is being pressed else if (Input.GetKey("a") && !isRoll) { // Changes the x-axis velocity of the player while retaining the y-axis velocity if (isCrouching) { rbody.velocity = new Vector3(-(moveSpeed / 2), rbody.velocity.y); } else { rbody.velocity = new Vector2(-(moveSpeed), rbody.velocity.y); } } // This else statement is to set the player's x-axis velocity to 0 if neither "a" nor "d" are being pressed. // Without this statement, the player would glide. else { if (!onMovingPlatform && !isRoll) { // Set player x-axis velocity to 0 while retaining y-axis velocity rbody.velocity = new Vector2(0, rbody.velocity.y); } else if (onMovingPlatform) { // Set player velocity to moving platform velocity rbody.velocity = new Vector2(mPVel, rbody.velocity.y); } } // Check if the space key is pressed AND that the player is on the ground if (Input.GetKey("space") && onGround) { // Retain current x-axis velocity, while adding a bit of y-axis velocity rbody.velocity = new Vector2(rbody.velocity.x, 6f); } isPassThroughBlock(); // Double tap down key to go down a pass through block if (Input.GetKeyDown(KeyCode.S)) { if (doubleTapDownTimer > 0 && doubleTapDownCount == 1 && currentPassThroughBlock != null /*Number of Taps you want Minus One*/) { currentPassThroughBlock.GetComponent <BoxCollider2D>().isTrigger = true; onGround = false; } else { doubleTapDownTimer = 0.5f; doubleTapDownCount += 1; } } if (doubleTapDownTimer > 0) { doubleTapDownTimer -= 1 * Time.deltaTime; } else { doubleTapDownCount = 0; } // Check if the "shift" key is pressed // Can only roll if grounded if (Input.GetKey(KeyCode.LeftShift) && isRoll == false && rollDelay <= 0) { // play the roll animation // Player is invisible for the duration of the roll isRoll = true; rollTimer = rollTime; invincibleTimer = 0.3f; takingDamage = true; rollDelay = 2f; //direction of roll // rolls right if (transform.localScale.x > 0) { //rbody.AddForce(new Vector2(3, 0)); rbody.velocity = new Vector2(3, rbody.velocity.y); } // rolls left else if (transform.localScale.x < 0) { //rbody.AddForce(new Vector2(-3, 0)); rbody.velocity = new Vector2(-3, rbody.velocity.y); } } // If on a ladder and press W, go up if (Input.GetKey("w") && onLadder) { rbody.velocity = new Vector2(rbody.velocity.x, 3); } // If on a ladder and press S, go down else if (Input.GetKey("s") && onLadder) { rbody.velocity = new Vector2(rbody.velocity.x, -3); } // Check if mouse key is pressed if (Input.GetMouseButton(0) && weapon != null) { // Fire bullet if (weapon.Shoot()) { // Knockback shootDirection = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; shootDirection.Normalize(); rbody.AddForce((-shootDirection * weapon.recoil), ForceMode2D.Force); } } // Check if weapon realod is pressed if (Input.GetKeyDown(KeyCode.R)) { weapon.Reload(); } // If player is not on the ground, countdown from timer if (!onGround) { fallTimer -= Time.deltaTime; } // This checks if the player has been falling for over 5 seconds // I have a timer variable set to 5, that counts down every time it is not touching the ground // If it touches the ground, the timer resets back to 5 seconds // This just moves the player back to the starting position // It doesn't reset the level, so the player can keep trying the level over and over again if (fallTimer <= 0) { ResetPlayer(); } // Check if player health is 0 if (health <= 0) { ResetPlayer(); } animationStates(); }
void Start() { switchScript2 = puzzleLevers[2].GetComponent <SwitchScript>(); switchScript1 = puzzleLevers[1].GetComponent <SwitchScript>(); switchScript = puzzleLevers[0].GetComponent <SwitchScript>(); }
// Use this for initialization void Start() { //SWをSwitchに関連付け _switch = GameObject.Find("Switch"); SW = _switch.AddComponent<SwitchScript>(); }
public EnemyWaveInput() { switchScript = gameObject.AddComponent <SwitchScript>(); switchScript.output = -1; }
public InputSetActiveScript() { switchScript = gameObject.AddComponent <SwitchScript>(); }
public ElevatorScript() { switchScript = gameObject.AddComponent <SwitchScript>(); }
void Awake() { Instance = this; }
// Use this for initialization void Start() { SpawnedEnemies = new List <GameObject>(); switchScript = GetComponentInChildren <SwitchScript>(); LevelDone = true; }