void Start() { waterScript = GameObject.Find("Target").GetComponent <TargetScript>(); movementScript = GameObject.Find("Player").GetComponent <Movement>(); InvokeRepeating("PassiveHydration", 0f, 0.01f); InvokeRepeating("ActiveHydration", 0f, 0.01f); }
void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag("Block")) { var speed = lastVelocity.magnitude; var direction = Vector2.Reflect(lastVelocity.normalized, other.contacts[0].normal); rb.velocity = direction * bulletSpeed; } else if (other.gameObject.CompareTag(tag = "Player")) { playerHit = true; //game.EndGame(); FindObjectOfType <GameManager>().EndGame(); } else if (other.gameObject.CompareTag(tag = "Target")) { targetHit = true; var speed = lastVelocity.magnitude; var direction = Vector2.Reflect(lastVelocity.normalized, other.contacts[0].normal); rb.velocity = direction * bulletSpeed; target = other.gameObject.GetComponent <TargetScript>(); target.Dead(); } }
void Shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) //origin of shot, direction of shit, where to save information, input range { Debug.Log(hit.transform.name); TargetScript target = hit.transform.GetComponent <TargetScript>(); //create instance of TargetScript from the component if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) //test that the RaycastHit object has a rigidbody { hit.rigidbody.AddForce(-hit.normal * impactForce); //hit.normal is perpendicular to face. we need force to go into face thus negative } Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); // GameObject impactEffectObject = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); //create reference to instantiated object through GameObject // Destroy(impactEffectObject, 2f); //delete the GameObject after 2 float seconds } }
public void SetTarget(int x, int y) { if (prefferedTarget == null) { test = true; prefferedTarget = new Point(x, y); Debug.Log(prefferedTarget); target = Instantiate(targetPrefab).GetComponent <TargetScript>(); target.SetPos(x, y); } else { if (x == prefferedTarget.x && y == prefferedTarget.y) { test = false; Destroy(target.gameObject); prefferedTarget = null; } else { test = true; prefferedTarget = new Point(x, y); target.SetPos(x, y); } } }
void ExplodeNeighbor(TargetScript neighbor) { if (neighbor != null) { level.DestroyTarget(neighbor); } }
void BlowUp() { GameObject effectGO = Instantiate(grenadeEffect, transform.position, transform.rotation); Destroy(effectGO, 2f); Collider[] colliders = Physics.OverlapSphere(transform.position, radius); //get all objects colliding with sphere foreach (Collider closeObject in colliders) { Rigidbody enemyRB = closeObject.GetComponent <Rigidbody>(); if (enemyRB != null) { enemyRB.AddExplosionForce(force, transform.position, radius); //apply explosion force } TargetScript target = closeObject.GetComponent <TargetScript>(); if (target != null) { target.RecieveDamage(45f); } } Destroy(gameObject); //destroy grenade }
void Shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); TargetScript target = hit.transform.GetComponent <TargetScript>(); if (target != null) { nextTimeToFire = Time.time + 1f / fireRate; target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 0.5f); } }
public void Shoot() { PlayParticles(); ApplyKick(); ammo -= 1; UpdateText(); audioSource.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { TargetScript target = hit.transform.GetComponent <TargetScript>(); if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 2f); } }
public void TargetSelectedUnit(TargetScript toSelect) { if (GameObjects == null) { GameObject.FindGameObjectWithTag("Andy"); } for (int i = 0; i < GameObjects.Length; i++) { TargetScript targetScript = GameObjects[i].GetComponent <TargetScript>(); targetScript.selected = false; targetScript.UpdateVisuals(); } if (toSelect != null) { SelectUnit.selected = true; SelectUnit.UpdateVisuals(); } else { TargetPanel.SetActive(false); } }
public void spawn() { TargetScript newKnight = Instantiate(Knight); newKnight.transform.position = transform.position; newKnight.Crystal = Crystal; }
public void PositionTargetPanel(TargetScript unit) { Vector3 pos = unit.gameObject.transform.position + Vector3.up * 2; TargetPanel.SetActive(true); TargetPanel.transform.position = Camera.main.WorldToScreenPoint(pos); }
public bool ColourTarget(Collider2D target, Colour colour) { TargetScript targetScript = target.GetComponent <TargetScript>(); if (targetScript.AttemptColouring(colour)) { targetsToColour--; if (targetsToColour <= 0) { if (canvasEnd != null) { canvasEnd.gameObject.SetActive(true); Time.timeScale = 0; } else { Debug.Log("canvasEnd NOT SET"); } } return(true); } return(false); }
void Start() { cloudsAnimator = GameObject.Find("Clouds").GetComponent <Animator>(); AddingCount = 2; AddingRate = 2f; Round = 1; wave1 = new Wave(); wave1.name = Round.ToString(); wave1.barrelGuy = barrelGuy1; wave1.count = AddingCount; wave1.rate = AddingRate; waves.Add(wave1); waterScript = GameObject.Find("Target").GetComponent <TargetScript>(); waveCountdown = timeBetweenWaves; scoreVisual.text = "Score: " + score.ToString(); wavenumber.text = "Wave: " + Round.ToString(); if (spawnPoints.Length == 0) { Debug.LogError("No spawn points referenceds"); } }
public void spawn() { TargetScript newPriest = Instantiate(Priest); newPriest.transform.position = transform.position; newPriest.Crystal = Crystal; }
void TriggerExplosion() { Vector3 explosionPos = transform.position; Collider[] colliders = Physics.OverlapSphere(explosionPos, 50f); foreach (Collider hit in colliders) { Debug.Log("Collided with : " + hit.gameObject.name); TargetScript target = hit.GetComponent <TargetScript>(); if (target != null && target.canShoot) { Rigidbody rb = hit.GetComponent <Rigidbody>(); Debug.Log("Missile Hit : " + rb.gameObject.name); target.TakeDamage(missileDamage); rb.AddExplosionForce(500f, explosionPos, 50f, 10f); } } SoundManagerScript.Instance.PlaySFX(SoundManagerScript.Instance.audioClipInfoList[3].audioClipID); Destroy(this.gameObject); }
void Start() { _target = GetComponent <TargetScript>(); _goTo = GetComponent <GoToTargetScript>(); _collect = GetComponent <CollectScript>(); _unload = GetComponent <UnloadScript>(); }
private void Start() { _target = GetComponent <TargetScript>(); _warrior = GetComponent <WarriorScript>(); _goTo = GetComponent <GoToTargetScript>(); _goTo = GetComponent <GoToTargetScript>(); _relationScript = GetComponent <RelationScript>(); }
void Start() { currentspeed = speedEnemy; target = GameObject.FindGameObjectWithTag("Water"); spawnPosition = GameObject.Find("Spawn Point"); targetScript = GameObject.Find("Target").GetComponent <TargetScript>(); player = GameObject.Find("Player"); }
void GunShoot() { muzzleFlash.SetActive(true); RaycastHit hit; GameObject instantiateBullet = Instantiate(bullet, transform.position + (Vector3.up * bulletPOS), Quaternion.identity) as GameObject; //instantiate another bullet Rigidbody instantiateBulletRB = instantiateBullet.GetComponent <Rigidbody>(); instantiateBulletRB.velocity = -transform.right * bulletSpeed; Invoke("DisplayMuzzle", 0.05f); //display muzzle flash Destroy(instantiateBullet, 7f); if (ammoMagCurrent > 0) { ammoMagCurrent -= 1; //reduce ammo } if (ammoMagCurrent <= 0 && ammoReserveCurrent >= ammoMagMax) //deplete ammo { StartCoroutine(Reload(3)); //start reload coroutine } else if (ammoMagCurrent <= 0 && ammoReserveCurrent < ammoMagMax) { StartCoroutine(Reload(1)); } if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, gunRange)) //if ray hits something within range { TargetScript target = hit.transform.GetComponent <TargetScript>(); EnemyController enemy = hit.transform.GetComponent <EnemyController>(); if (target != null) { target.RecieveDamage(gunDamage); if (hasPoison) //applies poison { StartCoroutine(ApplyPoison(target)); } } if (enemy != null) { //Debug.Log("got script"); if (hasSnare) //applies snare { StartCoroutine(ApplySnare(enemy)); } } GameObject hitGO = Instantiate(hitEffect, hit.point, Quaternion.LookRotation(hit.normal)); //display particle face upwards Destroy(hitGO, 2f); } }
void SpawnRandomEntity() { // we randomly get an entity from the array, and instantiate it in the scene. GameObject spawnedObject = Instantiate(GetGameObjectBasedOnProbability()) as GameObject; // compute a angle offset. this will ensure that the arc's center is always facing the player's initial orientation. float angleOffset = (180 - this.spawnAngle) / 2f; // The lower angle shall be at the offset + 0. defines the left side of the arc. lowerAngle = angleOffset; // The higher angle shall be at the offset + angle. defines the right side of the arc. higherAngle = this.spawnAngle + angleOffset; // chooses a random angle between the lower and the higher, i.e. a random point in the arc. float angle = Random.Range(lowerAngle, higherAngle); // does math magic to translate the angle to a point of a radius 1 circunference. Vector3 randomCircle = new Vector3(Mathf.Cos(angle * Mathf.Deg2Rad), 0, Mathf.Sin(angle * Mathf.Deg2Rad)); // multiplies the coordinate of the radius 1 circunference by the radius to obtain the coordinate in the actual circunference. Vector3 worldPos = transform.TransformPoint(randomCircle * radius); // set the gameobject (entity) position and look at the player. spawnedObject.transform.position = worldPos; spawnedObject.transform.LookAt(player.transform); if (ShouldAttachMoveComponent()) { AttachMoveComponent(spawnedObject, angle); } // we get the Target Script. we know all entities are targets and so, contain this script. TargetScript ts = spawnedObject.GetComponent <TargetScript>(); if (ts != null) { if (ts.GetType() == typeof(ScoreTarget)) { ((ScoreTarget)ts).scoreManager = this.scoreManager; } if (ts.GetType() == typeof(BonusTarget)) { ((BonusTarget)ts).bonusManager = this.bonusManager; } ts.timeToHide = timeUntilTargetDisappears; ts.player = this.player.transform; ts.desiredHeightOffset = GetRandomHeight(); // float halfAngle = (lowerAngle + higherAngle) / 2f; // //first sector. lerp from A0 (lower angle) to A1 (higher angle) (A0 -> min height, A1 -> max height); // if (angle < halfAngle) // { // ts.desiredHeightOffset = Mathf.Lerp(minHeight, maxHeight, Mathf.InverseLerp(lowerAngle, halfAngle, angle)); // the height will depend on the angle. // } // else // { // // second sector. lerp from A1 (higher angle) to A0 (lower angle). // ts.desiredHeightOffset = Mathf.Lerp(maxHeight, minHeight, Mathf.InverseLerp(halfAngle, higherAngle, angle)); // the height will depend on the angle. // } } }
private TargetScript SpawnTarget(GameObject spawnPoint) { GameObject newTarget = Instantiate(targetTemplate); TargetScript newTargetScript = newTarget.GetComponent <TargetScript>(); newTargetScript.SetManager(this); newTargetScript.SetPosition(transform.TransformPoint(spawnPoint.transform.position)); return(newTargetScript); }
public IEnumerator Should_ThrowArgumentException_When_GameObjectArrayRemainsEmpty() { TargetScript = DummyGameObject.AddComponent <ToggleGameObjects>(); FieldInfo = TargetScript.GetType().BaseType.GetField("_objects", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo.SetValue(TargetScript, new GameObject[] {}); TestSettings.ExpectException("ArgumentException:"); yield return(null); }
void OnTriggerEnter2D(Collider2D col) { TargetScript target = col.GetComponent <TargetScript>(); if (target != null) { target.Death(); APScript.UpScore(); } }
IEnumerator ApplyPoison(TargetScript target) { for (int i = 0; i < 4; i++) { yield return(new WaitForSeconds(2)); target.RecieveDamage(5); //Debug.Log("Damage"); } }
// Start is called before the first frame update void Start() { enemy = GetComponent <NavMeshAgent>(); player = GameObject.FindGameObjectWithTag("Player"); print(player.gameObject); potentialTargets = FindObjectsOfType <TargetScript>(); target = potentialTargets[Random.Range(0, potentialTargets.Length)]; InvokeRepeating("WalkingRoutine", 0, 5f); State = StateEnum.RUN; }
public IEnumerator Should_ThrowNullReferenceException_When_AtLeastOneGameObjectArrayElementIsNull() { TargetScript = DummyGameObject.AddComponent <ToggleGameObjects>(); FieldInfo = TargetScript.GetType().BaseType.GetField("_objects", BindingFlags.NonPublic | BindingFlags.Instance); var gameobjects = new GameObject[] { null }; FieldInfo.SetValue(TargetScript, gameobjects); TestSettings.ExpectException("NullReferenceException:"); yield return(null); }
private void Start() { renderer = GetComponent <SpriteRenderer>(); try{ if (target == null) { target = GetComponentInChildren <TargetScript>(); } //target = transform.GetChild(0).gameObject.GetComponent<TargetScript>(); } catch { // Ignore the error as it's just quality of life for me, not a need for the game } }
public IEnumerator Should_ContainOnlyActiveGameObjects_When_ScriptFullyInitialized() { TargetScript = DummyGameObject.AddComponent <ToggleGameObjects>(); FieldInfo = TargetScript.GetType().BaseType.GetField("_objects", BindingFlags.NonPublic | BindingFlags.Instance); var gameobjects = new[] { new GameObject(TypeName), new GameObject(TypeName) }; FieldInfo.SetValue(TargetScript, gameobjects); var actual = gameobjects[0].activeSelf && gameobjects[1].activeSelf; Assert.IsTrue(actual); yield return(null); }
// Start is called before the first frame update void Start() { gameStart = 0; player = SpawnPlayer(new Vector3(0f, 0.1f, 0f)); guards = new List <GuardScript>(); spawnPoints = GameObject.FindGameObjectsWithTag("Spawn Point"); for (int i = 0; i < 4; i++) { guards.Add(SpawnGuard(spawnPoints[i])); } target = SpawnTarget(spawnPoints[4]); }
public void DestroyTarget(TargetScript target) { target.Explode(); if (targets.Contains(target)) { targets.Remove(target); ui.targetCounter.SetCount(targets.Count); if (targets.Count == 0) { ui.successPanel.SetActive(true); } } }