//// Update is called once per frame //void Update () { //} public void SetupAttackPoint(AttackPointConfig _configData, DestroyableObject _parent) { parent = _parent; configData = _configData; attackPointType = configData.type; hp = configData.hp; }
private void HandleObjectDestroyed(string[] msg) { Scene currentScene = SceneManager.GetActiveScene(); if (currentScene.name == "ClientScene") { return; } string name = msg[1]; GameObject destroyableObject = GameObject.Find(name); if (!destroyableObject) { Debug.Log("Destroyable " + name + " does not exists"); return; } DestroyableObject destroyableController = destroyableObject.GetComponent <DestroyableObject>(); if (!destroyableController) { Debug.Log(name + " is not destroyable"); return; } destroyableController.DestroyMe(false); }
public void Plow() { if (this.m_Plant != null) { UnityEngine.Object.Destroy(this.m_Plant); this.m_Plant = null; } if (this.m_GrownPlant != null) { DestroyableObject component = this.m_GrownPlant.GetComponent <DestroyableObject>(); if (component) { component.DestroyMe(null, ""); } else { UnityEngine.Object.Destroy(this.m_GrownPlant); } this.m_GrownPlant = null; } if (this.m_ObjectWithTrunk != null) { UnityEngine.Object.Destroy(this.m_ObjectWithTrunk.gameObject); this.m_ObjectWithTrunk = null; } this.SetState(AcreState.Ready); this.m_WaterAmount = 0f; this.m_FertilizerAmount = 0f; this.m_AudioSource.PlayOneShot(Acre.s_PlowAudioClip); PlayerConditionModule.Get().GetDirtinessAdd(GetDirtyReason.Plow, null); }
public void OnBulletHit(GameObject Hit, Collision collision) { if (Hit.GetComponent <EnemyAI>() == null) { DestroyableObject target = Hit.transform.GetComponent <DestroyableObject>(); if (target != null) { ContactPoint point = collision.contacts[0]; Vector3 hitpoint = point.point; //target.TakeDamage(damage, hitpoint, this.gameObject); } Rigidbody hitRigid = Hit.transform.GetComponent <Rigidbody>(); Rigidbody rb = this.transform.GetComponent <Rigidbody>(); if (hitRigid != null) { if (rb != null) { if (hitRigid == rb) { return; } } hitRigid.AddForce(-collision.contacts[0].point * 100); } } }
/// <summary> /// Adds the health crate. /// </summary> public void addHealthCrate(GameObject zombieSpawner, int _difficulty) { int newDifficulty = _difficulty; //what the difficulty currently is GameObject goZ = (GameObject)Instantiate(Resources.Load("HealthBox")); //Instantiate the zombie prefab from resources //Assign to an enemyManager //1:Randomly choose an enemyManager es = GameObject.FindGameObjectsWithTag("Spawner"); //Es now contains all of the enemy spawners int emi = (int)Random.Range(0, es.Length); //stands for enemy manager index //2:Set parent child relationship Transform pT = es[emi].transform; //pt stands for parent transform goZ.transform.parent = pT; Vector3 spawnPos = zombieSpawner.transform.position; ///goZ.transform.position.x += es[emi].transform.localScale.x; ///goZ.transform.position.y += es[emi].transform.localScale.y; goZ.transform.position = spawnPos; DestroyableObject ZAI = goZ.GetComponent <DestroyableObject>(); //get words for this zombie. Upgrades knows the difficulty settting so it can effectively determine //how many words to give numWords = Difficulty_difficulty.getNumWords(); ZAI.setWords(dictionary.pickWords(int_difficulty, numWords * 10)); ZAI.setStats(int_difficulty, numWords); ZAI.setMeshWord(); }
void OnCollisionEnter(Collision coll) { if (coll.transform.tag == "Zombie") { DestroyableObject ZAI = coll.gameObject.GetComponent <DestroyableObject>(); if (ZAI.check(_word)) //if the words match up then we have hit our target //Do damage to this enemy { ZAI.hit(_weapon.getHitPower(), _weapon.getStunChance()); //Debug.Log ("Checking for splash damage position.x:" + transform.position.x + " position.y:" + transform.position.y); //Do splash damage GameObject [] allZombies = GameObject.FindGameObjectsWithTag("Zombie"); foreach (GameObject go in allZombies) { if (Vector2.Distance(go.transform.position, transform.position) < _range) { //Debug.Log ("Splashing Object:" + go.name); go.GetComponent <DestroyableObject>().splash(_splashDamage, _speedModifier, _knockback); } } } else if (_weapon.Penetrating) { ZAI.hit(_weapon.getHitPower(), _weapon.getStunChance()); } } if (!_weapon.Penetrating) { Destroy(gameObject); } }
public void Start() { if (photonView.IsMine != true) { return; } Camera.main.transform.SetParent(this.transform); Camera.main.transform.localPosition = new Vector3(0f, 0.25f, 1f); Camera.main.transform.localRotation = Quaternion.Euler(new Vector3(10f, 0f, 0f)); PhotonNetwork.RPC(photonView, "ChangeEnergyColor", RpcTarget.AllBuffered, false, new Vector3(EnergyColor.r, EnergyColor.g, EnergyColor.b), this.gameObject.GetPhotonView().ViewID); LastEnergyColor = EnergyColor; //jobsTransform.Add(this.transform); //Camera.main.transform.GetComponent<AlternateCameraScript>().target = this.transform; this.transform.position = new Vector3(0f, 0.5f, 0f); rigid = this.GetComponent <Rigidbody> (); desObj = this.GetComponent <DestroyableObject> (); if (CubeSettings.weapon != null) { weapon = CubeSettings.weapon; } }
public void OnBulletHitPosition(Vector3 pos) { Vector3 explosionPos = pos; explosionPos = new Vector3(explosionPos.x, explosionPos.y, -0.001f); Collider[] colliders = Physics.OverlapSphere(explosionPos, radius); foreach (Collider hit in colliders) { Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null) { //rb.velocity = Vector3.zero; //rb.angularVelocity = Vector3.zero; rb.AddExplosionForce(power, explosionPos, radius, upward); DestroyableObject destroyableObject = rb.GetComponent <DestroyableObject>(); if (destroyableObject != null) { rb.useGravity = true; destroyableObject.StartSelfDestroy(); this.gameMgr.OnGotScore(GameUIMgr.GotScoreType.SCORE_10, destroyableObject.gameObject); } //Debug.Log("hit " + rb.gameObject.name); } } }
void Awake() { // Animator anim = GetComponent<Animator>(); // anim.SetInteger("Health", CurrentHealth); if (gameObject.tag == TagsManager.Player) { Player = true; } if (gameObject.tag == TagsManager.DestroyableObject) { DestroybleObject = true; } switch (ArmorType) { case ArmorTypes.None: Hardness = 20f; break; case ArmorTypes.Lite: Hardness = 26f; break; case ArmorTypes.Medium: Hardness = 33.8f; break; case ArmorTypes.Heavy: Hardness = 43.94f; break; case ArmorTypes.Ultra: Hardness = 57.12f; break; } if (DestroybleObject) { MyDestroyableObject = GetComponent <DestroyableObject>(); ArmorType = ArmorTypes.None; Hardness = 10f; } }
private void Shoot() { if (isReloadAnimFinished && clipAmmoCount > 0) { animator.SetTrigger("gunSpin"); UseAmmo(); player.AddImpact(-fpsCam.transform.forward, backFireAmount); RaycastHit hitInfo; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hitInfo, range)) { DestroyableObject destroyableObject = hitInfo.transform.GetComponent <DestroyableObject>(); Enemy enemy = hitInfo.transform.GetComponentInParent <Enemy>(); if (hitInfo.transform.gameObject.tag == "DestroyableObject") { destroyableObject.gameObject.GetComponent <BoxCollider>().enabled = false; destroyableObject.ExplodeObject(); } else if (hitInfo.transform.gameObject.tag == "Enemy") { enemy.TakeDamage(damage); } } } }
public void ArmorUpgrade() { Debug.Log("UPGRADED ARMOR!"); if (cubeToUpgrade != null && ArmorUpgrades.Count > 0) { ScoreSystem.Score -= CurrentArmorUpgrade.Cost; DestroyableObject desObj = cubeToUpgrade.GetComponent <DestroyableObject>(); ShootShots shootShots = cubeToUpgrade.GetComponent <ShootShots>(); //desObj.maxHealth += CurrentArmorUpgrade.modifier; //desObj.health = desObj.maxHealth; if (CurrentArmorUpgrade.upgradePrefab != null) { //Transform cube = GameObject.FindObjectOfType<PlayerCube>().transform; //cube.position = new Vector3(cube.position.x, cube.position.y + 0.2f, cube.position.z); GameObject upgradePrefab = PhotonNetwork.Instantiate("Armor/" + CurrentArmorUpgrade.upgradePrefab.name, cubeToUpgrade.transform.position, cubeToUpgrade.transform.rotation, 0); upgradePrefab.transform.parent = GameObject.FindObjectOfType <PlayerCube>().transform.Find("ArmorHolder").transform; Transform cube = GameObject.FindObjectOfType <PlayerCube>().transform; cube.position = new Vector3(cube.position.x, cube.position.y + 0.2f, cube.position.z); foreach (Transform child in upgradePrefab.transform) { //child.gameObject.AddComponent<Rigidbody>(); //Rigidbody body = child.GetComponent<Rigidbody>(); //body.useGravity = false; //body.mass = 10; //child.position = new Vector3(child.position.x, child.position.y - 0.2f, child.position.z); //body.isKinematic = false; } } int upgradeIndex = ArmorUpgrades.IndexOf(CurrentArmorUpgrade); ArmorUpgrades.RemoveAt(upgradeIndex); } }
protected virtual RaycastHit[] Shoot(int numberOfShots) { trail.Play(); trail.Emit(10); RaycastHit hit; DestroyableObject obj = null; RaycastHit[] hitArray = new RaycastHit[numberOfShots]; AudioController.instance.PlayRandomSound(shots, AudioController.instance.weapon); for (int i = 0; i < numberOfShots; i++) { Vector3 shotPos = new Vector3(Random.Range(-xSpread, xSpread), Random.Range(-ySpread, ySpread), 0f) + cam.transform.forward; if (Physics.Raycast(cam.transform.position, shotPos, out hit, range)) { Debug.Log(hit.collider.name); hitArray [i] = hit; obj = hit.transform.GetComponent <DestroyableObject> (); Explosion _exlposion = hit.transform.GetComponent <Explosion> (); Enemy _enemy = hit.transform.GetComponent <Enemy> (); PlayerSettings player = hit.transform.GetComponentInChildren <PlayerSettings>(); Turret turret = hit.transform.GetComponentInParent <Turret>(); if (turret != null) { turret.ApplyDamage(damage, hit); } if (player != null && player.isAlive) { player.ApplyDamage(damage); } if (_exlposion != null && !_exlposion.exploaded) { _exlposion.Explode(); _exlposion.exploaded = true; } if (obj != null && !obj.wasHit && _exlposion == null) { obj.ApplyDamage(obj.health); obj.wasHit = true; } if (_enemy != null && _enemy.isAlive) { enemyHitted = true; _enemy.ApplyDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * force); } NoiseController.instance.SpreadNoise(shotVolume / 2, hit.transform.position); } } NoiseController.instance.SpreadNoise(shotVolume, transform.position); return(hitArray); }
//// Update is called once per frame //void Update () { //} public void SetupUI(DestroyableObject _targetObj) { if (targetObj != null) { targetObj.onHPUpdate -= TargetObj_OnHPUpdate; } targetObj = _targetObj; if (progressBar == null) { GameObject progressBarPrefab = GameUtility.GetProgressBarPrefab(); GameObject progressBarGo = Instantiate(progressBarPrefab); progressBarGo.transform.SetParent(panel); progressBarGo.transform.localPosition = new Vector3(0.0f, 30.0f, 0.0f); progressBarGo.transform.localScale = Vector3.one; progressBar = progressBarGo.GetComponent <ProgressBarScript>(); } progressBar.SetupProgressBar(null, null, targetObj.hp, targetObj.hp); CreateNumberTextObjectPool(); targetObj.onHPUpdate += TargetObj_OnHPUpdate; }
[PunRPC] public void respawn(int viewID) { Transform thisObject = PhotonView.Find(viewID).transform; DestroyableObject desObj = thisObject.GetComponent <DestroyableObject>(); desObj.isAlive = true; thisObject.gameObject.SetActive(true); thisObject.position = new Vector3(0f, 0.5f, 0f); }
//public void Update() { //model.transform.position = Vector3.Lerp(model.transform.position, proxy.transform.position, Time.deltaTime * 2); //model.transform.rotation = Quaternion.Lerp(model.transform.rotation, proxy.transform.rotation, Time.deltaTime * 5); //} public void Shoot(bool beam) { RaycastHit hit; if (beam == false) { if (blast != null) { blast.Play(); } } if (beam == true) { if (blast != null) { model.transform.GetChild(1).GetComponent <ParticleSystem> ().Play(); } } float properRange = 20f; if (beam == true) { properRange = 30f; } if (Physics.Raycast(model.transform.position, model.transform.forward, out hit, properRange)) { DestroyableObject desObj = hit.transform.GetComponent <DestroyableObject> (); Rigidbody hitRigid = hit.transform.GetComponent <Rigidbody> (); if (hit.transform.GetComponent <EnemyAI>() == null) { if (beam == false) { if (desObj != null) { //desObj.TakeDamage (damage, hit.point, this.gameObject); } } if (beam == true) { if (desObj != null) { //desObj.TakeDamage (1000f, hit.point, this.gameObject); } if (hitRigid != null) { hitRigid.AddForce(hit.point * 100); } } } } }
void PlayerSpawnLargeBox(Player player, TypeOfGun.myType type) { DestroyableObject largeBox = Instantiate(ServerManager.instance.objectsToSpawn[3]).GetComponent <DestroyableObject>(); largeBox.transform.position = player.gun.transform.position; largeBox.transform.right = player.transform.right; largeBox.playerId = player.connectionId; largeBox.Setup(lifeLargeBox); NetworkServer.Spawn(largeBox.gameObject); }
// Perform a Raycast Shot protected virtual RaycastHit Shoot() { RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range, ~(1 << LayerMask.NameToLayer("GunLayer")))) { DestroyableObject obj = hit.transform.GetComponent <DestroyableObject> (); Explosion _exlposion = hit.transform.GetComponent <Explosion> (); Enemy _enemy = hit.transform.GetComponent <Enemy> (); PlayerSettings player = hit.transform.GetComponentInChildren <PlayerSettings>(); Turret turret = hit.transform.GetComponentInParent <Turret>(); if (turret != null) { turret.ApplyDamage(damage, hit); } if (obj != null) { obj.ApplyDamage(damage); } if (player != null && player.isAlive && !transform.parent.GetComponentInParent <PlayerSettings>()) { player.ApplyDamage(damage / 2); } if (_enemy != null && _enemy.isAlive) { enemyHitted = true; _enemy.ApplyDamage(damage, hit); } else { enemyHitted = false; } if (_exlposion != null) { _exlposion.Explode(); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * force); } NoiseController.instance.SpreadNoise(shotVolume / 2, hit.transform.position); } else { } NoiseController.instance.SpreadNoise(shotVolume, transform.position); return(hit); }
protected void DestroyObject(GameObject other) { DestroyableObject destroyable = other.GetComponent <DestroyableObject>(); if (destroyable.reinforced && !enhanced) { return; } destroyable.DestroyMe(true); }
public void SetupCharacter(CharacterConfig _characterConfig, DestroyableObject _targetObject) { if (_characterConfig != null) { characterConfig = _characterConfig; } transform.position = _targetObject.front.position; RegisterTargetObject(_targetObject); CreateWeapon(characterConfig.defaultWeapon); }
void CreateObject(int _objectIndex) { ObjectConfig objectConfig = levelConfig.objects[_objectIndex]; GameObject objectGO = Instantiate(Resources.Load <GameObject>(objectConfig.prefab)); currentObject = objectGO.GetComponent <DestroyableObject>(); currentObject.SetupObject(objectConfig); cameraController.RegisterDestroyableObject(currentObject.transform); if (characterController != null) { characterController.RegisterTargetObject(currentObject); } }
void OnTriggerEnter(Collider col) { DestroyableObject dO = col.GetComponent("DestroyableObject") as DestroyableObject; if (dO != null) { foreach (int destroyLayer in destroyableLayers) { if (destroyLayer == dO.destroyableLayerIndex) { Destroy(col.gameObject); } } } }
protected override void Activate() { base.Activate(); transform.Find("Sprite").GetComponent <SpriteRenderer>().sprite = spineOn; if (currentPos == null) { Teleport(new Position((int)transform.position.x, (int)transform.position.y)); } DestroyableObject desObj = (DestroyableObject)MapManager.instance.Find(typeof(DestroyableObject), currentPos); if (desObj != null) { desObj.Destroy(); } }
public void Shoot() { --ammo; shootParticle.Play(); Ray ray = _cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit, maxDistance, mask)) { DestroyableObject dsObject = hit.transform.GetComponent <DestroyableObject>(); dsObject?.DestroyObject(); } canUse(ammo > 0); }
void OnParticleCollision(GameObject other) { int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents); if (other.GetComponent <DestroyableObject>()) { DestroyableObject obj = other.GetComponent <DestroyableObject>(); obj.PartPlay(collisionEvents[0].intersection); obj.hp -= damage; if (obj.rigidbodyForces) { obj.gameObject.GetComponent <Rigidbody2D>().AddForce((-collisionEvents[0].intersection + other.transform.position).normalized * 60); } } }
public void shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { test.Play(); Debug.Log(hit.transform.name); DestroyableObject ob = hit.transform.GetComponent <DestroyableObject>(); if (ob != null) { ob.getHit(damage); } } }
void SetUpFields() { m_target = Camera.main.transform; m_healthContext = GetComponentInParent <DestroyableObject>(); m_healthText = GetComponentInChildren <TMPro.TMP_Text>(); m_healthBarSlider = GetComponentInChildren <Image>(); if (m_healthContext == null) { Debug.LogError($"HealthContext is null - {gameObject}"); } else { m_healthContext.HealthChanged += OnHealthChange; OnHealthChange(m_healthContext.m_maxHealth); } }
public IEnumerator shoot(bool beamMode) { RaycastHit hit; if (weapon == null) { if (beamMode == false) { this.transform.Find("Blast").GetComponent <ParticleSystem>().Play(); } else { this.transform.Find("Beam").GetComponent <ParticleSystem>().Play(); } if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, range)) { DestroyableObject desObj = hit.transform.GetComponent <DestroyableObject>(); Rigidbody hitRigid = hit.transform.GetComponent <Rigidbody>(); if (hit.transform.GetComponent <EnemyAI>() == null) { if (desObj != null) { if (beamMode == false) { //desObj.TakeDamage(damage, hit.point, this.gameObject); } else { //desObj.TakeDamage(1000f, hit.point, this.gameObject); } if (hitRigid != null) { hitRigid.AddForce(-hit.point * 10); } } } } } else { yield return(null); } }
IEnumerator Regenerate() { DestroyableObject desObj = model.GetComponent <DestroyableObject>(); while (true) { //if (desObj.health < desObj.maxHealth && timeScinceLastTimeTakingDamage >= 5f) //{ // desObj.health += 750; // yield return new WaitForSeconds(1f); //} //else //{ // yield return null; //} } }
private void OnCollisionEnter(Collision collision) { if (isCollision) { // Apply the force to the rigibody ignoring the mass collision.rigidbody.AddForceAtPosition(directionForce * forceApply, collision.transform.position, ForceMode.VelocityChange); // Reset the collision isCollision = false; // Take damage to the object DestroyableObject destroyableObject = collision.collider.gameObject.GetComponent <DestroyableObject>(); if (destroyableObject) { destroyableObject.TakeDamage(punchDamage); } } }
public void SpeedUpgrade() { Debug.Log("UPGRADED SPEED!"); if (cubeToUpgrade != null && SpeedUpgrades.Count > 0) { ScoreSystem.Score -= CurrentSpeedUpgrade.Cost; DestroyableObject desObj = cubeToUpgrade.GetComponent <DestroyableObject>(); ShootShots shootShots = cubeToUpgrade.GetComponent <ShootShots>(); cubeToUpgrade.speed += CurrentSpeedUpgrade.modifier; if (CurrentSpeedUpgrade.upgradePrefab != null) { GameObject upgradePrefab = PhotonNetwork.Instantiate("Armor/" + CurrentSpeedUpgrade.upgradePrefab.name, cubeToUpgrade.transform.position, cubeToUpgrade.transform.rotation, 0); upgradePrefab.transform.SetParent(cubeToUpgrade.transform); } int upgradeIndex = SpeedUpgrades.IndexOf(CurrentSpeedUpgrade); SpeedUpgrades.RemoveAt(upgradeIndex); } }