public void Knockback(LightSource lightSource) { if (lightSource is Player) { Transform player = lightSource.transform; Rigidbody playerRigidbody = player.GetComponent <Rigidbody>(); this.controllerRumble = player.GetComponent <ControllerRumble>(); // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (player.position - gameObject.transform.position); Vector2 knockback = distance.normalized * knockbackForce; playerRigidbody.velocity = Vector3.zero; playerRigidbody.AddForce(knockback, ForceMode.Impulse); // Instantiate hit particles GameObject.Instantiate(hitParticles, player.position, Quaternion.Euler(0, 0, 0)); FlashColor(probeColorHit, hitFlashDuration); // Rumble the controller when the player hits a fish. controllerRumble.PlayerHitByFish(); // The player was just hit // lastTimeHit = Time.time; } }
public void Knockback(LightSource lightSource) { if (lightSource is Player) { Transform player = lightSource.transform; Rigidbody playerRigidbody = player.GetComponent<Rigidbody>(); this.controllerRumble = player.GetComponent<ControllerRumble>(); // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (player.position - gameObject.transform.position); Vector2 knockback = distance.normalized * knockbackForce; playerRigidbody.velocity = Vector3.zero; playerRigidbody.AddForce(knockback, ForceMode.Impulse); // Instantiate hit particles GameObject.Instantiate(hitParticles, player.position, Quaternion.Euler(0, 0, 0)); FlashColor(probeColorHit, hitFlashDuration); // Rumble the controller when the player hits a fish. controllerRumble.PlayerHitByFish(); // The player was just hit // lastTimeHit = Time.time; } }
void Start() { laser = GetComponent <LaserBehaviour>(); sequencer = GameObject.FindGameObjectWithTag("Sequencer").GetComponent <TrackSequencer>(); judger = GetComponent <LaserMIDITimingJudge>(); visualizer = GetComponentInChildren <LaserNoteVisualier>(); rumble = GetComponent <ControllerRumble>(); model = this.transform.Find("Model").gameObject; modelInitialScale = model.transform.localScale; }
/// <summary> /// Initialize Player components /// <see cref="Unity Documentation"> /// </summary> protected override void Awake() { base.Awake(); this.controllerRumble = GetComponent <ControllerRumble>(); this.playerSound = GetComponent <PlayerSound>(); this.movement = new PlayerMovement(movementBean, this.Transform, this.Rigidbody, this.LightEnergy); this.lightToggle = new PlayerLightToggle(this.Transform.Find("LightsToToggle").gameObject, this, lightToggleBean); this.flareControl = new PlayerSpawnFlare(flareBean, this, controllerRumble); this.movementBean.DefaultDrag = Rigidbody.drag; this.isDead = false; this.isSafe = true; }
void Start() { this.timer = cooldownTime; this.lightSource = GetComponent<LightSource>(); this.controllerRumble = GetComponent<ControllerRumble>(); this.rigidbody = GetComponent<Rigidbody>(); player = GameObject.FindWithTag("Player").transform; playerSound = player.GetComponent<PlayerSound>(); GameObject mainCamera = GameObject.Find("Main Camera"); if (mainCamera != null) { this.smoothCamera = mainCamera.GetComponent<SmoothCamera>(); } }
/// <summary> /// Initializes Player components /// </summary> protected override void Awake() { base.Awake(); // call parent LightSource Awake() first if (playerInstance != null && playerInstance != this) { GameObject.Destroy(this.gameObject); } else { DontDestroyOnLoad(this.gameObject); playerInstance = this; } this.movement = new PlayerMovement(massEjectionTransform, lightBallPrefab, thrustForce, changeDirectionBoost, thrustEnergyCost, brakeDrag, this.Transform, this.Rigidbody, this.LightEnergy, this.jetFuelEffect, this.rotationSpeed); this.lightToggle = new PlayerLightToggle(this.Transform.Find("LightsToToggle").gameObject, defaultLightStatus, this, minimalEnergyRestrictionToggleLights, propulsionLightRange); this.materials = new MaterialExtensions(); this.defaultDrag = Rigidbody.drag; this.isDead = false; this.isSafe = true; this.controllerRumble = GetComponent <ControllerRumble>(); playerSound = GetComponent <PlayerSound>(); this.currentLevel = SceneManager.GetActiveScene().buildIndex; ChangeColor(probeColorOff, false, 0); LoadGame(); ResetPlayerState(); gameOverCanvas = GameObject.FindWithTag("GameOverCanvas"); UI = GameObject.FindWithTag("UI"); if (gameOverCanvas == null) { Canvas[] canvases = UI.GetComponentsInChildren <Canvas>(); foreach (Canvas canvas in canvases) { if (canvas.name == "GameOverCanvas") { gameOverCanvas = canvas.gameObject; break; } } } #if UNITY_EDITOR this.ValidateInputs(); #endif }
void Start() { this.timer = cooldownTime; this.lightSource = GetComponent <LightSource>(); this.controllerRumble = GetComponent <ControllerRumble>(); this.rigidbody = GetComponent <Rigidbody>(); player = GameObject.FindWithTag("Player").transform; playerSound = player.GetComponent <PlayerSound>(); GameObject mainCamera = GameObject.Find("Main Camera"); if (mainCamera != null) { this.smoothCamera = mainCamera.GetComponent <SmoothCamera>(); } }
public PlayerSpawnFlare(FlareBean flareBean, Player player, ControllerRumble controllerRumble) { this.timer = 0; this.cooldownTime = flareBean.CoolDown; this.flareSpawnObject = flareBean.FlareSpawnObject; this.recoilForce = flareBean.RecoilForce; this.flareCostPercentage = flareBean.FlareCostPercentage; this.flareEnergyCost = flareBean.FlareEnergyCost; this.player = player; this.controllerRumble = controllerRumble; this.rigidbody = player.GetComponent <Rigidbody>(); GameObject mainCamera = GameObject.Find("Main Camera"); if (mainCamera != null) { this.smoothCamera = mainCamera.GetComponent <SmoothCamera>(); } }
/// <summary> /// Initializes Player components /// </summary> protected override void Awake() { base.Awake(); // call parent LightSource Awake() first if (playerInstance != null && playerInstance != this) { GameObject.Destroy(this.gameObject); } else { DontDestroyOnLoad(this.gameObject); playerInstance = this; } this.movement = new PlayerMovement(massEjectionTransform, lightBallPrefab, thrustForce, changeDirectionBoost, thrustEnergyCost, brakeDrag, this.Transform, this.Rigidbody, this.LightEnergy, this.jetFuelEffect, this.rotationSpeed); this.lightToggle = new PlayerLightToggle(this.Transform.Find("LightsToToggle").gameObject, defaultLightStatus, this, minimalEnergyRestrictionToggleLights, propulsionLightRange); this.materials = new MaterialExtensions(); this.defaultDrag = Rigidbody.drag; this.isDead = false; this.isSafe = true; this.controllerRumble = GetComponent<ControllerRumble>(); playerSound = GetComponent<PlayerSound>(); this.currentLevel = SceneManager.GetActiveScene().buildIndex; ChangeColor(probeColorOff, false, 0); LoadGame(); ResetPlayerState(); gameOverCanvas = GameObject.FindWithTag("GameOverCanvas"); UI = GameObject.FindWithTag("UI"); if (gameOverCanvas == null) { Canvas[] canvases = UI.GetComponentsInChildren<Canvas>(); foreach (Canvas canvas in canvases) { if (canvas.name == "GameOverCanvas") { gameOverCanvas = canvas.gameObject; break; } } } #if UNITY_EDITOR this.ValidateInputs(); #endif }