public static bool SpawnEffectOnCollide( GameObject target, SpellPrefabManager src, GameObject effect, List <string> ignore = null, bool reverse_ignore = false) { if (ignore != null) { if (GameplayStatics.ObjHasTag(target, ignore, reverse_ignore)) { return(false); } } if (src) { if (target != src.GetOwner() && !SpellVerifySameOwnership(target, src.GetOwner())) { GameObject fx = MonoBehaviour.Instantiate(effect); fx.transform.position = GameplayStatics.GetTriggerContactPoint(target, src.gameObject); return(true); } } return(false); }
//void OnTriggerEnter(Collider other) //{ // if(other.tag == "Player" || other.name == "Player") // { // GameplayStatics.DealDamage(other.gameObject, 1); // } //} void OnCollisionEnter(Collision other) { if (other.collider.tag == "Player" || other.collider.name == "Player") { GameplayStatics.DealDamage(other.gameObject, 1); } }
private void OnTriggerEnter(Collider other) { if (other.tag == "Player" && !GameManager.Instance.isImmortality) { GameplayStatics.DealDamage(other.gameObject, 1); } }
public void TakeDamage(float amount, GameplayStatics.DamageType type = GameplayStatics.DamageType.Normal) { if (!m_IsInvincible) // if the target can take damage { m_CurrentHealth -= amount; // reduce your health m_CurrentHealth = Mathf.Clamp(m_CurrentHealth, 0.0f, m_MaxHealth); if (m_CurrentHealth <= 0.0f && m_OnDeath != null) { m_OnDeath.Invoke(); //if the actor is dead, call death event } if (m_OnTakeDamage != null) { m_OnTakeDamage.Invoke(amount, type); // call take damage event } var col = gameObject.GetComponent <Collider2D>(); var pos = col.bounds.center + col.bounds.extents; // pos = transform.position; if (m_DamagePopupOverride == GameplayStatics.DamageType.Null) { GameplayStatics.SpawnDmgPopup(pos + new Vector3(0, 0, -5), amount, type); } else { GameplayStatics.SpawnDmgPopup(pos + new Vector3(0, 0, -5), amount, m_DamagePopupOverride); } StartCoroutine(FlashSprite(m_HitFlashDuration)); // flash the sprite material if it can if (m_CanUseIFrames) // if the actor can use i frames { m_IsInvincible = true; // make it invincible for the iframe duration StartCoroutine(StartIFrame(m_IFrameTime)); } } }
private void OnTriggerEnter(Collider other) { // if other is ColoredWalls if (other.CompareTag("Walls")) { // ColoredWalls Ref (this gameobject is Cylinder) MeshRenderer coloredWallsColor = other.gameObject.GetComponent <MeshRenderer>(); nextTower = 1 + other.gameObject.transform.parent.parent.GetComponentInParent <TowerObjectPulling>().TowerNumber; // if player color is the same as one of the walls that collide OR player is immortal if (currentColor.material.name == coloredWallsColor.material.name || GameManager.Instance.isImmortality) { if (totalTriggered == 0) // AVOID DOUBLE TRIGGER { totalTriggered++; StartCoroutine(delayWallTrigger(0.15f)); // delay it, to avoid getting killed from changing color while still inside the walls } } else { GameplayStatics.DealDamage(gameObject, 1); } } // For Coins and Diamonds if (other.CompareTag("Coins")) { IncreaseCoins(other.gameObject); } }
void SwordState() { if (Input.GetMouseButtonDown(0) && timeToAttack <= 0) { swordAnim.SetBool("IsAttacking", true); timeToAttack = timeToAttackValue; Collider[] enemiesToDmg = Physics.OverlapSphere(attackPos.position, attackRange, whatIsEnemies); for (int i = 0; i < enemiesToDmg.Length; i++) { // collider.gameObject ==> since this collider is from gameobject GameplayStatics.DealDamage(enemiesToDmg[i].gameObject, slashDmg); Debug.Log("HIt"); if (enemiesToDmg[i].gameObject.tag == "LumberJack") // check if the enemy is LumberJack then we can do jumpbuff; { timeToJumpBuff = 0; } } } else { swordAnim.SetBool("IsAttacking", false); timeToAttack -= Time.deltaTime; } }
public static bool DestroyOnCollide( GameObject target, SpellPrefabManager src, List <string> ignore = null, bool reverse_ignore = false) { if (ignore != null) { if (GameplayStatics.ObjHasTag(target, ignore, reverse_ignore)) { return(false); } } if (src) { if (target != src.GetOwner() && !SpellVerifySameOwnership(target, src.GetOwner())) { GameObject.Destroy(src.gameObject); return(true); } } return(false); }
public static void PullTargetToSrc( GameObject target, GameObject src, float pull_str, List <GameObject> objs_to_ignore, List <string> tags_to_ignore, bool negate_ignore = false) { if (GameplayStatics.ObjHasTag(target, tags_to_ignore, negate_ignore)) { return; } if (target.GetComponent <Rigidbody2D>() && !GameplayStatics.IsObjInList(target.gameObject, objs_to_ignore)) { Vector3 pos = src.transform.position; Vector3 enemy = target.transform.position; Vector3 dir = pos - enemy; dir.Normalize(); Vector3 newpos = (dir * 0.001f * pull_str); newpos = new Vector3(newpos.x, newpos.y, 0); target.transform.position += newpos; //target.GetComponent<Rigidbody2D>().velocity = Vector2.zero; //target.GetComponent<Rigidbody2D>().angularVelocity = 0.0f; //target.GetComponent<Rigidbody2D>().AddForce(dir * m_PullStrength); } }
public static bool CastSpellOnCollide( GameObject target, SpellPrefabManager src, Spell spell, Vector3?spawn_pos = null, List <string> ignore = null, bool reverse_ignore = false) { if (ignore != null) { if (GameplayStatics.ObjHasTag(target, ignore, reverse_ignore)) { return(false); } } if (src) { if (target != src.GetOwner() && !SpellVerifySameOwnership(target, src.GetOwner())) { spell.CastSpell(src.GetOwner(), target, spawn_pos); return(true); } } return(false); }
private void SetUpAvatarAndTransformAccordingToType() { string prafabName = "PhotonNetworkPlayerTest"; // Check If it contains this player type { if (!NetPlayerSetting.Instance.Type2PrefabName.ContainsKey(myType)) { GameplayStatics.LogError("Fail to find relevant type [" + myType + "] in prefab folders, fail to create VR Player"); } else { // Set proper name prafabName = NetPlayerSetting.Instance.Type2PrefabName[myType]; } } // Set up Player base transform Transform playerStart = NetworkReferences.Instance.m_PlayerStartPositions[(int)myType]; if (PV.IsMine) { // Set up avatar transform myAvatar = PhotonNetwork.Instantiate(/*Resources.Load<GameObject>*/ (Path.Combine("PhotonPrefabs", prafabName)), playerStart.position, playerStart.rotation); PV.RPC("SetUpLocalAvatar", RpcTarget.AllBuffered, myAvatar.GetComponent <PhotonView>().ViewID, prafabName); } }
public static bool DamageOnCollide( GameObject target, SpellPrefabManager src, float damage, List <string> ignore = null, GameplayStatics.DamageType type = GameplayStatics.DamageType.Normal) { if (ignore != null) { if (GameplayStatics.ObjHasTag(target, ignore)) { return(false); } } if (src) { if (target != src.GetOwner() && !SpellVerifySameOwnership(target, src.GetOwner())) { GameplayStatics.ApplyDamage(target, damage, type); return(true); } } return(false); }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag != "Player") { return; } GameplayStatics.DealDamage(collision.gameObject, 1); }
private IEnumerator FindClosestObject() { while (true) { var CurrentBearFloor = GameplayStatics.GetCurrentFloorOfObject(this.gameObject); if (AttackObject != null) { //clears out the attack object if it's too far away if (Vector3.Distance(transform.position, AttackObject.gameObject.transform.position) > maxDistToObject) { AttackObject.ClearHighlight(); AttackObject = null; } } var destructableEnumerator = GameObject.FindObjectsOfType <InteractableObject>() .Where(obj => !obj.bIsDestroyed); foreach (var item in destructableEnumerator) { if (CurrentBearFloor != GameplayStatics.GetCurrentFloorOfObject(item.gameObject)) { continue; } var newObjPos = Vector3.Distance(transform.position, item.gameObject.transform.position); if (newObjPos < maxDistToObject) { if (AttackObject != null) { var attackObjPos = Vector3.Distance(transform.position, AttackObject.gameObject.transform.position); if (newObjPos > attackObjPos) { AttackObject.ClearHighlight(); AttackObject = item; } } else { AttackObject = item; } } } if (AttackObject != null) { AttackObject.SetHighlight(); } //Sleep for a bit and do this all again yield return(new WaitForSeconds(asyncLookupThreadSleep)); } yield return(null); }
protected override void SetupAsRemotePlayer() { base.SetupAsRemotePlayer(); GameplayStatics.Log("Surgeon setup as remote player, my Type: " + NetPlayerSetting.Instance.MyType); // Destroy local component Destroy(m_VRGO); Destroy(GetComponent <OVRDebugInfo>()); }
private bool ShouldCollide(Collider2D other) { var gameObj = other.gameObject; var rockCollide = !ignoreRock && (gameObj).CompareTag("Rock"); var shouldNotIgnore = (rockCollide || GameplayStatics.ObjHasTag(gameObj, TagsToIgnore, true)); var ignoreInstantiator = shouldNotIgnore && !other.gameObject.CompareTag(_instantiatorTag); return(ignoreInstantiator); }
protected override void SetupAsLocalPlayer() { base.SetupAsLocalPlayer(); GameplayStatics.Log("RemoteOP setup as local player, my Type: " + NetPlayerSetting.Instance.MyType); // Initialize remote operator parameters m_Camera.tag = "MainCamera"; Camera.SetupCurrent(m_Camera); }
protected override void SetupAsRemotePlayer() { base.SetupAsRemotePlayer(); GameplayStatics.Log("RemoteOP setup as remote player, my Type: " + NetPlayerSetting.Instance.MyType); // Destroy local component Destroy(m_Camera.gameObject); Destroy(m_CanvasObj); }
public void Heal(float amount, GameplayStatics.DamageType type = GameplayStatics.DamageType.Heal) { m_CurrentHealth += amount; m_CurrentHealth = Mathf.Clamp(m_CurrentHealth, 0.0f, m_MaxHealth); GameplayStatics.SpawnDmgPopup(transform.position, amount, type, false); if (m_OnReceiveHeal != null) { m_OnReceiveHeal.Invoke(amount, type); } }
private void Awake() { if (_instance != null && _instance != this) { Destroy(gameObject); } else { _instance = this; } }
public override void OnTick(GameObject obj) { var manager = obj.GetComponent <SpellPrefabManager>(); if (!manager.m_Target) { Destroy(obj); return; } GameplayStatics.ApplyDamage(manager.m_Target, m_Damage, GameplayStatics.DamageType.Fire); }
public override void SpellTriggerEnter(Collider2D target, GameObject src) { GameObject target_obj = target.gameObject; SpellPrefabManager s_manager = src.GetComponent <SpellPrefabManager>(); if (target_obj != s_manager.GetOwner() && GameplayStatics.ObjHasTag(target_obj, SpellUtilities.room)) { GameObject.Destroy(src); } }
public override void SpellCollisionEnter(Collision2D target, GameObject src) { Debug.Log("CollisionEnter"); GameObject target_obj = target.gameObject; SpellPrefabManager s_manager = src.GetComponent <SpellPrefabManager>(); SpellUtilities.CastSpellOnCollide(target.gameObject, s_manager, m_SpellToCast, spawn_pos: GameplayStatics.GetTriggerContactPoint(target.gameObject, src), SpellUtilities.invalid); if (target_obj != s_manager.GetOwner() && !GameplayStatics.ObjHasTag(target_obj, SpellUtilities.invalid)) { GameObject.Destroy(src); } }
IEnumerator OnDieBehaviour() { Move(Vector3.zero); anim.Play("Dead"); capsule.height = 0.2f; capsule.center = new Vector3(0, 0.3f, 0); AudioSource.PlayClipAtPoint(dieSound, transform.position); OnDeath.Invoke(); yield return(new WaitForSeconds(3)); GameplayStatics.RestartLevel(); }
public bool CastSpell(GameObject target = null) { if (!m_Spell) { return(false); } GameObject actual_target = m_Spell.m_CastType == SpellCastType.FireAndForget ? target : m_Owner; //if the spell is not on CD or it has charges if ((!m_IsSpellOnCD || m_RemainingCharges > 0) && !m_IsConcentrating && !m_Spell.m_UseAllAvailableCharges) { m_IsConcentrating = m_Spell.m_CastType == SpellCastType.Concentration; m_InstantiatedSpell = m_Spell.CastSpell(m_Owner, actual_target, m_SpawnPoint.position, m_SpawnParent.rotation); m_RemainingCharges--; // only update cooldown if it's not already on cooldown // i.e when there's no charges left if (!m_IsSpellOnCD) { m_RemainingCD = m_Spell.m_SpellCooldown; } m_IsSpellOnCD = true; return(true); } else if (m_Spell.m_UseAllAvailableCharges && !m_UsingCharges && m_RemainingCharges > 0) { m_IsConcentrating = m_Spell.m_CastType == SpellCastType.Concentration; m_RemainingCD = m_Spell.m_SpellCooldown; m_IsSpellOnCD = true; float delay = 0.05f; float ttl = delay * m_RemainingCharges * 1.1f; GameplayStatics.Delay(delay * m_RemainingCD * 1.1f, () => m_UsingCharges = true, () => m_UsingCharges = false); GameplayStatics.AddTimer(m_Owner, ttl, delay, () => { if (m_RemainingCharges > 0) { m_InstantiatedSpell = m_Spell.CastSpell(m_Owner, actual_target, m_SpawnPoint.position, m_SpawnParent.rotation); m_RemainingCharges--; } }); return(true); } else if (m_IsConcentrating) { m_Spell.StopConcentration(m_InstantiatedSpell); m_IsConcentrating = false; } return(false); }
public override GameObject CastSpell(GameObject owner, GameObject target = null, Vector3?spawn_pos = null, Quaternion?spawn_rot = null) { if (m_Prefab && owner) { Vector3 dir = ((Quaternion)spawn_rot * Vector3.right).normalized; Vector3 rot_dir = ((Quaternion)spawn_rot * Vector3.up).normalized; Quaternion rot = GameplayStatics.GetRotationFromDir(rot_dir); Vector3 target_pos = owner.transform.position + dir * 8.5f; Vector3 spawn_position = spawn_pos != null ? (Vector3)spawn_pos : owner.transform.position; float distance = (spawn_position - target_pos).magnitude; Debug.DrawRay(spawn_position, dir * distance, Color.green, 1.0f); RaycastHit2D[] hit = Physics2D.CircleCastAll(spawn_position, 2.0f, dir, distance, layerMask: GameplayStatics.LayerEnemy); foreach (RaycastHit2D enemy in hit) { GameplayStatics.ApplyDamage(enemy.collider.gameObject, m_Damage); } hit = Physics2D.CircleCastAll(spawn_position, 2.0f, dir, distance, layerMask: LayerMask.GetMask("FlyingEnemy"));; foreach (RaycastHit2D enemy in hit) { GameplayStatics.ApplyDamage(enemy.collider.gameObject, m_Damage); } GameObject obj = Instantiate(m_Prefab); obj.GetComponent <SpellPrefabManager>().SetOwner(owner); obj.tag = "SpellUninteractive"; Destroy(obj.GetComponent <BoxCollider2D>()); obj.transform.position = spawn_position + dir * distance / 2; obj.transform.rotation = rot; obj.transform.localScale = new Vector2(1.5f, distance); // GameplayStatics.AddQuad(obj, m_Material); if (m_Material) { obj.GetComponent <MeshRenderer>().material = m_Material; obj.GetComponent <SpellPrefabManager>().AddOnUpdate((objt) => { SpellPrefabManager spm = objt.GetComponent <SpellPrefabManager>(); objt.GetComponent <MeshRenderer>().material.SetFloat("_Strength", spm.m_TimeToLive - spm.m_TimeAlive); }); } obj.GetComponent <SpellPrefabManager>().m_TimeToLive = m_SpellDuration; obj.GetComponent <SpellPrefabManager>().AddTriggerTick(this.SpellTriggerTick); obj.GetComponent <SpellPrefabManager>().AddOnUpdate(this.OnTick); } return(null); }
public void AutoAim() { Vector3 pos = this.gameObject.transform.position; float thresh = 0.7f; Collider2D[] overlaps = Physics2D.OverlapCircleAll(pos, AutoAimRange); float min_dist = Mathf.Infinity; GameObject old_target = target; target = null; foreach (Collider2D overlap in overlaps) { if (overlap.gameObject.CompareTag("Enemy")) { Vector2 hit_pos = new Vector2(overlap.gameObject.transform.position.x, overlap.gameObject.transform.position.y); Vector2 sub = new Vector2(pos.x - hit_pos.x, pos.y - hit_pos.y); if (min_dist > sub.magnitude + thresh) { target = overlap.gameObject; min_dist = sub.magnitude; } } } if (target != null) { // Vector3 target_center = target.GetComponent<Collider2D>().bounds.center; Vector3 target_center = target.transform.position; Vector2 dir = (target_center - gameObject.transform.position).normalized; //Vector2 dir = (target_center - m_FirePoint.transform.position).normalized; m_MovementComponent.FlipSprite(dir.x); Quaternion rot = GameplayStatics.GetRotationFromDir(dir); m_PlayerHand.GetComponent <SpriteRenderer>().transform.rotation = rot; target.GetComponentInChildren <TargetHighlightComponent>().ToggleHighlight(true); if (old_target) { if (old_target != target) { var shadow = old_target.GetComponentInChildren <TargetHighlightComponent>(); if (shadow) { shadow.ToggleHighlight(false); } } } } m_SpellComponent.SetTarget(target); }
public override GameObject CastSpell(GameObject owner, GameObject target = null, Vector3?spawn_pos = null, Quaternion?spawn_rot = null) { if (m_Prefab && owner) { Vector3 dir = target == null ? ((Quaternion)spawn_rot * Vector3.right).normalized : (target.transform.position - owner.transform.position).normalized; Quaternion rot = GameplayStatics.GetRotationFromDir(dir); Vector2 speed = new Vector2(m_ProjectileSpeed * dir.x, m_ProjectileSpeed * dir.y); GameObject obj = SpellUtilities.InstantiateSpell(m_Prefab, owner, target, this, (Vector3)spawn_pos, rot, spell_velocity: speed, tag: "SpellUninteractive"); return(obj); } return(null); }
public override void Death(GameObject Instigator) { if (isDead) { return; } base.Death(Instigator); //Shield = 0; //Stop execution if we have lives to add if (Lives <= 0 && Health <= 0) { if (FullDeath != null) { FullDeath(); } return; } Invulnerable = true; Lives--; LifeLost(); //Dealing radial damage to all enemies nearby GameplayStatics.DealRadialDamage(DeathDamageRadius, transform.position, 100, EDamageType.ALL, gameObject); //Destroying all projectiles Collider[] bullets = Physics.OverlapSphere(transform.position, 100.0f);//, 12); foreach (Collider bullet in bullets) { PL_Bullet bulletscript = bullet.gameObject.GetComponent <PL_Bullet>(); if (bulletscript && bullet.gameObject.tag == "EnemyProjectile") { bulletscript.SpawnEffects(); Destroy(bullet.gameObject); } } if (OnLivesAdded != null) { OnLivesAdded(Lives); } Invoke("ResetHealth", invulnerableTime); }
public override GameObject CastSpell(GameObject owner, GameObject target = null, Vector3?spawn_pos = null, Quaternion?spawn_rot = null) { if (m_Prefab && owner) { Vector3 dir = target == null ? ((Quaternion)spawn_rot * Vector3.right).normalized : (target.transform.position - owner.transform.position).normalized; Quaternion rot = GameplayStatics.GetRotationFromDir(dir); Vector2 speed = new Vector2(0, 0); GameObject obj = SpellUtilities.InstantiateSpell(m_Prefab, owner, target, this, (Vector3)spawn_pos, Quaternion.identity, spell_velocity: speed, tick_delay: m_TickDealay, tag: "SpellUninteractive"); var sprite = obj.GetComponent <SpriteRenderer>(); if (sprite) { sprite.enabled = false; } var manager = obj.GetComponent <SpellPrefabManager>(); if (m_TickBehaviors.Count > 0 && m_TickBehaviors[0] != null) { manager.m_TickDelay = m_TickBehaviors[0].m_Delay; } foreach (var behaviour in m_TickBehaviors) { if (behaviour.m_SCData.m_RemoveOnModified) { UnityAction <float, GameplayStatics.DamageType> action = (dmg, type) => Destroy(obj); manager.GetOwner().GetComponent <StatusComponent>().AddOnTakeDamage((dmg, type) => { action(dmg, type); // status.RemoveOnTakeDamage(action); }); } } //obj.GetComponent<SpellPrefabManager>().SetFollowerOwner(FollowWho.Player); //var status = obj.GetComponent<SpellPrefabManager>().GetOwner().GetComponent<StatusComponent>(); //UnityAction<float, GameplayStatics.DamageType> action = (dmg, type) => Destroy(obj); //status.AddOnTakeDamage( (dmg, type) => { // action(dmg, type); // status.RemoveOnTakeDamage(action); //}); return(obj); } return(null); }
protected override void SetupAsLocalPlayer() { base.SetupAsLocalPlayer(); GameplayStatics.Log("Surgeon setup as local player, my Type: " + NetPlayerSetting.Instance.MyType); // 1. Main Camera m_MainCam.tag = "MainCamera"; // 2. Destroy Remote Component // Destroy local player's Mesh and the sync camera comp Destroy(m_LHandTr_Remote.GetChild(0).gameObject); Destroy(m_RHandTr_Remote.GetChild(0).gameObject); Destroy(m_Camera_Remote.GetComponent <Camera>()); Destroy(m_AvatarDisplay); }