// Update is called once per frame void Update() { if (running && remainingTime > 0) { timeText.text = remainingTime.ToString("0.00"); remainingTime -= Time.deltaTime; } if (remainingTime <= 0) { HealthHandler p1Health = GameObject.FindGameObjectWithTag("Player 1").GetComponent <HealthHandler> (); HealthHandler p2Health = GameObject.FindGameObjectWithTag("Player 2").GetComponent <HealthHandler> (); fightUI.enabled = false; gameOverUI.enabled = true; if (p1Health.curHP > p2Health.curHP) { gameOverText.text = "Player 1 Wins!"; } else if (p1Health.curHP < p2Health.curHP) { gameOverText.text = "Player 2 Wins!"; } else { gameOverText.text = "Tie!"; } Time.timeScale = 0; } }
void Start() { spriteRenderer = this.gameObject.GetComponent <SpriteRenderer>(); soundSource = GetComponent <AudioSource>(); soundSource.clip = soundEffect; switch (type) { case PowerUpType.Health: case PowerUpType.Shield: healthHandler = GameObject.FindObjectOfType <HealthHandler>(); break; case PowerUpType.Super_Edginess: case PowerUpType.Points: edginessHandler = GameObject.FindObjectOfType <EdginessHandler>(); break; case PowerUpType.Bullet: polyShooter = GameObject.FindObjectOfType <PolyShooter>(); break; default: Destroy(this); break; } powerUpManager = GameObject.FindObjectOfType <PowerUpManager>(); StartCoroutine(FadePowerUp()); Invoke("DestroySelf", 10f); }
private void Awake() { character = GetComponent <Character>(); healthHandler = GetComponent <HealthHandler>(); healthHandler.SetMaxHealth(character.maxHealth); movementType = Character.MovementType.MoveToPoint; character.movementType = movementType; foreach (Transform point in patrolPointsObject.GetComponentInChildren <Transform>()) { patrolPoints.Add(point.position); } machine = GetComponentInChildren <StateMachine>(); character.stateList = new List <State>() { new State_Idle(character), new State_Patrol(character, patrolPoints, patrolPointsObject.transform, roamRadius, patrolType), new State_Chase(character), new State_Search(character, this, 100f, 10f), new State_Attack(character), new State_Interact(character), }; character.stateMachine = machine; character.stateMachine.startState = character.stateList[0]; //machine.SetState(stateList[1]); }
public IEnumerator LoseTarget(float waitTime) { yield return(new WaitForSeconds(waitTime)); targetEnemy = null; targetHealth = null; }
// Start is called before the first frame update void Start() { health = 100.0f; initialTime = Time.time; healthHandler = GameObject.FindObjectOfType <HealthHandler>(); healthHandler.updateSlider(); }
private void OnSceneLoaded(Scene loadedScene, LoadSceneMode loadSceneMode) { switch (loadedScene.buildIndex) { // Main Menu case 0: //GameObject.Find("Start Button").GetComponent<Button>().onClick.AddListener(() => StartGame()); break; // In-game case 1: m_pauseMenu = GameObject.FindGameObjectWithTag("PauseMenu"); m_skillMenu = GameObject.FindGameObjectWithTag("SkillMenu"); m_skillMenuBackground = GameObject.Find("SkillMenuBackground"); m_player = GameObject.FindGameObjectWithTag("Player").GetComponent <BaseCharacter>().m_healthHandler; m_pauseMenu.SetActive(false); m_skillMenu.SetActive(false); m_skillMenuBackground.SetActive(false); break; case 2: GameObject.Find("Return").GetComponent <Button>().onClick.AddListener(() => QuitToMainMenu()); break; } Debug.Log("Level Loaded"); }
// Start is called before the first frame update void Start() { player = FindObjectOfType <PlayerController>(); health = GetComponent <HealthHandler>(); scoreHandler = FindObjectOfType <ScoreHandler>(); AddNoneTriggerBoxCollider(); }
public void spawnCharacter() { GameObject g = Instantiate(character, gameObject.transform.position, gameObject.transform.rotation); p1Controls = g.GetComponent <P1_MovementController> (); p2Controls = g.GetComponent <P2_MovementController> (); ProjectileReceiver pr = g.GetComponent <ProjectileReceiver> (); HealthHandler hh = g.GetComponent <HealthHandler> (); if (gameObject.name == "P1Spawner") { p1Controls.enabled = true; p1Controls.specialSlider = specialSlider; p1Controls.shieldSlider = shieldSlider; p2Controls.enabled = false; Destroy(g.GetComponent <P2_MovementController>()); } if (gameObject.name == "P2Spawner") { p1Controls.enabled = false; p2Controls.specialSlider = specialSlider; p2Controls.shieldSlider = shieldSlider; p2Controls.enabled = true; Destroy(g.GetComponent <P1_MovementController>()); } pr.buffSlide = bufferSlider; pr.bufferText = bufferText; hh.healthSlider = healthSlider_ref; }
private void Start() { health = new HealthHandler(enemyProperties.totalHealth); health.Died += OnDied; GameManager.Instance.GameEnd += OnGameEnd; }
// Start is called before the first frame update void Start() { healthScript = GameObject.FindGameObjectWithTag("GameHandler").GetComponent <HealthHandler>(); control = GameObject.FindGameObjectWithTag("Player").GetComponent <Control>(); engineScript = GameObject.Find("EngineParent").GetComponent <EngineEvent>(); dialogueScript = GameObject.Find("QuestionHandler").GetComponent <Dialogue>(); }
// Start is called before the first frame update protected virtual void Start() { soundSource = GetComponent <AudioSource>(); soundSource.clip = soundEffect; player = GameObject.FindObjectOfType <PlayerMovement>().transform; edginessHandler = GameObject.FindObjectOfType <EdginessHandler>(); healthHandler = GameObject.FindObjectOfType <HealthHandler>(); }
// Start is called before the first frame update void Start() { _health = this.gameObject.GetComponent <HealthHandler>(); _method = OnDeath; _renderer = this.gameObject.GetComponent <SpriteRenderer>(); _health.RegisterDeathMethod(_method); _defend.Add(this); }
// Use this for initialization void Start() { _PlayerLives = GameObject.FindGameObjectWithTag("Player").GetComponent <HealthHandler> (); if (_PlayerLives == null) { print("No PlayerLives Detected in Scene @SceneManager"); } }
void Start() { spawner = GetComponent <Respawn> (); rb = GetComponent <Rigidbody>(); col2D = GetComponent <Collision>(); hp = GetComponent <HealthHandler>(); facingRight = true; }
private int _currentLives; //private variable of current lives // Use this for initialization void Start() { _lives = GameObject.Find(_target).GetComponent <HealthHandler> (); //Find the Target GameObject if (_lives == null) //If there is no Lives found { print("NO " + _target + " FOUND IN SCENE! @HealthUI"); //Print Error if the are no Lives found } }
void Start() { InARange = false; healthHandler = GameObject.Find("Scripts").GetComponent <HealthHandler>(); Damage = 3f; StartCoroutine(InRange()); }
// Use this for initialization void Start() { _input = GameObject.Find("GameController").GetComponent <InputHandler> (); _health = GetComponent <HealthHandler> (); _move = GetComponent <MovementHandler> (); _shoot = GetComponent <ShootHandler> (); _collision = GetComponent <CollisionHandler> (); }
public static void AddHealth(Component entity, int health) { HealthHandler handler = entity.GetComponent <HealthHandler>(); if (handler) { handler.AddHealth(health); } }
public void Construct(Navigator navigator, HealthHandler healthHandler, BehaviorHandler behaviorHandler, Player player) { _navigator = navigator; _healthHandler = healthHandler; _behaviorHandler = behaviorHandler; _player = player; return; }
public void AssignTarget(Transform targetT) { if (targetEnemy == null) { targetEnemy = targetT; targetHealth = targetEnemy.GetComponent <HealthHandler>(); StartCoroutine(LoseTarget(changeTargetInterval)); } }
// Update is called once per frame void Update() { // left mouse button click if (playerScript) { if (Input.GetButtonDown("Fire1") | Input.GetButton("Fire1")) { if (Time.time > lastFireTime + 1 / frequency) { // Spawn visual bullet //Quaternion tempRot = Quaternion.LookRotation(playerScript.GetMouseOnPlane() - muzzlePosition.position , Vector3.forward); //tempRot.z = 0f; //tempRot.w = 0.5f; Quaternion tempRot = transform.parent.transform.rotation; Quaternion coneRandomRotation = Quaternion.Euler(Random.Range(-coneAngle, coneAngle), Random.Range(-coneAngle, coneAngle), 0); GameObject go = (GameObject)Instantiate(bulletPrefab, muzzlePosition.position, tempRot * coneRandomRotation); SimpleBullet bullet = go.GetComponent <SimpleBullet> (); muzzleParticle.Emit(1); lastFireTime = Time.time; // Find the object hit by the raycast RaycastHit hitInfo = new RaycastHit(); Physics.Raycast(transform.position, transform.parent.forward, out hitInfo, 100); if (hitInfo.transform) { // Get the health component of the target if any HealthHandler targetHealth = hitInfo.transform.GetComponent <HealthHandler> (); if (targetHealth & (hitInfo.transform.root != transform.root)) { // Apply damage targetHealth.DeductHealth(Mathf.FloorToInt(damagePerSecond / frequency)); } // Get the rigidbody if any if (hitInfo.rigidbody) { // Apply force to the target object at the position of the hit point Vector3 force = transform.forward * (forcePerSecond / frequency); hitInfo.rigidbody.AddForceAtPosition(force, hitInfo.point, ForceMode.Impulse); } bullet.dist = hitInfo.distance; } else { bullet.dist = 1000; } } } } }
void Start() { debounce = false; delta = 0f; _health = gameObject.GetComponent <HealthHandler>(); _method = DeathMethod; _health.RegisterDeathMethod(_method); _collider = this.gameObject.GetComponent <BoxCollider2D>(); }
public void FindTarget() { if (target) { RaycastHit hit; if (Physics.Raycast(AutoTurretPos.position, ((target.GetBody.position + Vector3.up) - AutoTurretPos.position).normalized, out hit, AutoTurretRange, AutoTurretSightMask)) { if (hit.transform != target) { target = null; } } else { target = null; } if (target && target.isDead) { target = null; } } if (target) { return; } Collider[] colliders = Physics.OverlapSphere(AutoTurretPos.position, AutoTurretRange, AutoTurretMask); foreach (var item in colliders) { RaycastHit hit; if (Physics.Raycast(AutoTurretPos.position, ((item.transform.position + Vector3.up) - AutoTurretPos.position).normalized, out hit, AutoTurretRange, AutoTurretSightMask)) { if (hit.collider == item) { HealthHandler handler = item.GetComponent <HealthHandler>(); if (!handler) { ColliderHit hitCollider = item.GetComponent <ColliderHit>(); if (hitCollider) { handler = hitCollider.healthScript; } } if (!handler) { continue; } if (handler.isDead) { continue; } target = handler; return; } } } }
private Vector3 _velocityState; //Private Vector3 for the current Velocity // Use this for initialization void Start() { _input = GameObject.Find("GameController").GetComponent <InputHandler> (); //Find the GameControllers InputHandler _health = GetComponent <HealthHandler> (); //Find the HealthHandler _healthAnimator = GetComponent <HealthAnimator>(); _move = GetComponent <MovementHandler> (); //Find the MovementHandler _shoot = GetComponentInChildren <WeaponsInputProcessor> (); //Find the ShootHandler _trigger = GetComponent <TriggerHandler> (); //Find the TriggerHandler _collision = GetComponent <CollisionHandler>(); }
private void SetHealthInUI(HealthHandler handler) { for (var i = 0; i < handler.MaxHealth; i++) { var healthState = i < handler.Health; thumbs[i].gameObject.SetActive(healthState); } amount.text = $"x{handler.Health}"; }
private void Awake() { health = new HealthHandler(PlayerProperties.playerTotalHealth); health.HealthUpdate += OnHealthUpdate; health.Died += OnPlayerDied; OnHealthUpdate(PlayerProperties.playerTotalHealth); weaponFactory = new WeaponFactory(); IntializeStateMachine(); }
private void Awake() { m_LocalNetworkTogglables = GetComponent <LocalNetworkTogglables>(); m_PlayerNetworkHandler = GetComponent <PlayerNetworkHandler>(); m_RevealActor = GetComponent <RevealActor>(); m_StealthActor = GetComponent <StealthActor>(); m_SkillHandler = GetComponent <SkillHandler>(); m_HealthHandler = GetComponent <HealthHandler>(); m_CharacterCustomizer = GetComponentInChildren <CharacterCustomizer>(); }
public static bool DeductHealth(Component entity, int health) { HealthHandler handler = entity.GetComponent <HealthHandler>(); if (handler) { return(handler.DeductHealth(health)); } return(false); }
// Start is called before the first frame update void Start() { if (m_player == null) { m_player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>(); } m_healthHandler = m_player.m_healthHandler; m_levelHandler = m_player.m_levelHandler; }
// Use this for initialization void Start() { gameObject.tag = "Player 2"; FlipFacing(); anim = GetComponent <Animator> (); rb = GetComponent <Rigidbody2D> (); stats = GetComponent <CharTraits> (); maxSpeed = stats.walkspeed; jumpHeight = stats.jumpheight; projectile = stats.projectile; shieldSlider.maxValue = 5.0f; specialSlider.maxValue = 5.0f; specialSlider.value = specialSlider.maxValue; p1 = GameObject.FindGameObjectWithTag("Player 1"); if (p1 != null) { Debug.Log("p1 isn't null"); if (p1.gameObject.GetComponent <P1_MovementController> ().p2 == null) { Debug.Log("Trying to manually set p1 through p2"); p1.gameObject.GetComponent <P1_MovementController> ().p2 = gameObject; if (p1.gameObject.GetComponent <P1_MovementController> ().p2 == gameObject) { Debug.Log("Successfully set p1's reference to p2. Manually resetting p1's p2Health"); p1.gameObject.GetComponent <P1_MovementController> ().p2Health = gameObject.GetComponent <HealthHandler> (); } } p1Health = p1.GetComponent <HealthHandler> (); Debug.Log("p1 health is " + p1Health); } else { Debug.Log("p1 is null!"); } // TOTAL BULL SHIT WORK AROUND p1.GetComponent <P1_MovementController>().p2 = gameObject; foreach (Transform child in transform) { GameObject g = (GameObject)(child.gameObject); // Debug.Log ("Found game object " + g.name + " in P2"); g.tag = "Player 2 ext"; foreach (Transform grandchild in g.transform) { grandchild.gameObject.tag = "Player 2 ext"; } } }
void Start() { target = GameObject.FindWithTag ("Player").transform; healtScript = (HealthHandler)target.GetComponent<HealthHandler>(); myAgent = GetComponent<NavMeshAgent>(); }