public GameObject SpawnProjectileFromPool(ProjectileType projectileType, Vector3 position, Quaternion rotation) { if (!m_ProjectilePoolDictionary.ContainsKey(projectileType)) { Debug.LogError("Pool of " + projectileType + " dosen't exist."); return(null); } if (m_ProjectilePoolDictionary[projectileType].Count == 0) { Debug.LogError(projectileType.ToString() + " pool is empty!"); return(null); } GameObject objectToSpawn = m_ProjectilePoolDictionary[projectileType].Dequeue(); objectToSpawn.transform.position = position; objectToSpawn.transform.rotation = rotation; objectToSpawn.SetActive(true); PoolTracker poolTracker = AddPoolTrackerComponent(objectToSpawn, PoolType.ProjectileType); poolTracker.ProjectileType = projectileType; m_TrackedObject.Enqueue(poolTracker); return(objectToSpawn); }
public GameObject SpawnObj(ProjectileType key) { if (!PoolDictionary.ContainsKey(key)) { Debug.Log("Dictionary does not contain this key: " + key.ToString()); return(null); } GameObject objToSpawn = null; for (int i = 0; i < PoolDictionary[key].Count; i++) { objToSpawn = PoolDictionary[key].Dequeue(); if (objToSpawn.activeSelf) { PoolDictionary[key].Enqueue(objToSpawn); objToSpawn = null; continue; } else if (!objToSpawn.activeSelf) { objToSpawn.SetActive(true); PoolDictionary[key].Enqueue(objToSpawn); break; } } if (objToSpawn == null) { Debug.Log("No Projectiles available to Spawn"); } return(objToSpawn); }
public static BaseProjectile SpawnProjectile(ProjectileType projectileType) { if (projectileType == ProjectileType.Invalid) { Debug.Log("<color=red>PROJECTILE not defined !!!! please check asap !!! </color>"); Debug.Break(); return(null); } return(GetObjectFromPool(projectileType.ToString(), projectileDataPath) as BaseProjectile); }
/// <summary> /// Gets the projectile sprite for the given projectile type /// </summary> /// <param name="type">the projectile type</param> /// <returns>the projectile sprite for the type</returns> public static Texture2D GetProjectileSprite(ProjectileType type) { // replace with code to return correct projectile sprite based on projectile type if (type.ToString() == "FrenchFries") { return(frenchFriesSprite); } else { return(teddyBearProjectileSprite); } }
public void SpawnProjectile(ProjectileType type, Vector3 position, Vector3 target) { for (int i = 0; i < this.Spawners.Length; i++) { ProjectileSpawner spawner = this.Spawners[i]; if (spawner.Type == type) { spawner.Spawn(position, target); return; } } Debug.LogError("SpawnProjectile no spawner for " + type.ToString()); }
public void ResetProjectile(ProjectileType proj) { stats.Clear(); stats.Add(new NameValue("Damage", Utilities.DamageOf(proj).ToString())); stats.Add(new NameValue("Speed", Utilities.SpeedOf(proj).ToString())); stats.Add(new NameValue("Sell Value", GameInfo.SellValueOf(proj).ToString() + "c")); stats.Add(new NameValue("", "")); stats.Add(new NameValue("Effects", Utilities.TextEffectsOf(proj))); name = proj.ToString().AddSpaces(); desc = Utilities.GetDescOf(proj); Position(); }
// Use this for initialization private void Start() { _cannon = GameObject.Find(ProjectileType.ToString() + "Cannon").GetComponent <Cannon>(); _forces = GameObject.Find("Environment Forces").GetComponent <EnvironmentForces>(); // Compoenent Initial velocity // Vx = Vi * Cos(Theta) // Vy = Vi * Sin(Theta) _velocity.x = _cannon.Velocity * Mathf.Cos(Mathf.Deg2Rad * _cannon.Angle); _velocity.y = _cannon.Velocity * Mathf.Sin(Mathf.Deg2Rad * _cannon.Angle); if (ProjectileType == ProjectileType.Goat) { _velocity.x = -_velocity.x; } }
void OnCollisionEnter(Collision coll) { Debug.Log("type: " + type.ToString()); if (type == ProjectileType.Kinetic) { try { coll.gameObject.GetComponent <Health>().DealDamage(detonationDamage); } catch { Debug.Log("NO HEALTH SCRIPT"); } Destroy(gameObject); Debug.Log("DESTROYING PROJECTILE"); } }
public ProjectileInfoHover(ProjectileType proj, SpriteFont font, GraphicsDevice graphics, int windowWidth) : base(graphics, font, proj.ToString().AddSpaces(), Utilities.GetDescOf(proj), new List <NameValue>(), windowWidth) { stats.Add(new NameValue("Damage", Utilities.DamageOf(proj).ToString())); stats.Add(new NameValue("Speed", Utilities.SpeedOf(proj).ToString())); stats.Add(new NameValue("Sell Value", GameInfo.SellValueOf(proj).ToString() + "c")); stats.Add(new NameValue("", "")); // Ensures that Effects stat is on a new line stats.Add(new NameValue("Effects", Utilities.TextEffectsOf(proj))); for (int i = 0; i < stats.Count; i++) { statLocs.Add(new Vector2()); } Position(); }
public GameObject SpawnToPosRot(ProjectileType key, Vector3 spawnPosition, Quaternion spawnRotation) { if (!PoolDictionary.ContainsKey(key)) { Debug.Log("Dictionary does not contain this key: " + key.ToString()); return(null); } GameObject objToSpawn = null; for (int i = 0; i < PoolDictionary[key].Count; i++) { objToSpawn = PoolDictionary[key].Dequeue(); if (objToSpawn.activeSelf) { PoolDictionary[key].Enqueue(objToSpawn); objToSpawn = null; continue; } else if (!objToSpawn.activeSelf) { objToSpawn.SetActive(true); objToSpawn.transform.position = spawnPosition; objToSpawn.transform.rotation = spawnRotation; PoolDictionary[key].Enqueue(objToSpawn); break; } } if (objToSpawn == null) { Debug.Log("No Projectiles available to Spawn"); } return(objToSpawn); }
private GameObject SelectProjectile() { if (Input.GetKeyDown(KeyCode.Space)) { switch (_selectedProjectile) { case ProjectileType.Small: _selectedProjectile = ProjectileType.Medium; break; case ProjectileType.Medium: _selectedProjectile = ProjectileType.Large; break; case ProjectileType.Large: _selectedProjectile = ProjectileType.Small; break; } } SelectedProjectilePrefab = _projectiles[_selectedProjectile.GetHashCode()]; _missileTypeText.text = _selectedProjectile.ToString(); return(SelectedProjectilePrefab); }
public static BasicProjectile SpawnProjectile(ProjectileType type) { BasicProjectile projectile = (Resources.Load(projectileDataPath + type.ToString()) as GameObject).GetComponent <BasicProjectile>(); return(projectile); }
private void CalculateFiringGroup() { float lastDelay = 0; float delayUpToThisPoint = 0; ProjectileType lastType = ProjectileType.Straight; if (TargetPlayerInsteadOfFireDirections) { for (int x = 0; x < TargetPlayer_NumberOfShotsToFire; x++) { Vector3 directionToPlayer = GameObject.FindGameObjectWithTag("Player").transform.position - transform.position; directionToPlayer.Normalize(); ProjectileType type = ProjectileType.Straight; if (UseRandomProjectileTypes) { type = (ProjectileType)Random.Range(0, 2); Debug.Log(type.ToString()); } else if (ProjectileTypes.Count > x) { type = ProjectileTypes[x]; } StartCoroutine(FireProjectile(directionToPlayer, delayUpToThisPoint + lastDelay, type)); delayUpToThisPoint += lastDelay; float delay = GetNextAvailableDelay(x); if (delay != -1) { lastDelay = delay; } } } else if (UseDegreesFiring) { for (int x = 0; x < FireDirectionsInDegrees.Count; x++) { if (ProjectileTypes.Count > x) { lastType = ProjectileTypes[x]; } StartCoroutine(FireProjectile((FireDirectionsInDegrees[x] + DegreesOffset).DegreeToVector2(), delayUpToThisPoint + lastDelay, lastType)); delayUpToThisPoint += lastDelay; float delay = GetNextAvailableDelay(x); if (delay != -1) { lastDelay = delay; } } } else { for (int x = 0; x < FireDirections.Count; x++) { if (ProjectileTypes.Count > x) { lastType = ProjectileTypes[x]; } StartCoroutine(FireProjectile(FireDirections[x], delayUpToThisPoint + lastDelay, lastType)); delayUpToThisPoint += lastDelay; float delay = GetNextAvailableDelay(x); if (delay != -1) { lastDelay = delay; } } } }
public virtual bool Fire(GetTarget targetFunc) { if (!reloading) { if (!OnCooldown) { if (Magazine > 0) { for (int i = 0; i < ProjectilesPerShot; ++i) { Vector3 bulletEndPos = targetFunc(); bulletEndPos += ((isAimed) ? AimedSpread : Spread) * Random.insideUnitSphere; BaseProjectile nProjectile = Instantiate <BaseProjectile>(Resources.Load <BaseProjectile>("Projectiles/" + BulletType.ToString())); nProjectile.transform.position = Muzzle.position; nProjectile.transform.LookAt(bulletEndPos); nProjectile.SetUpProjectile(MuzzleVelocity, Damage); } FiredGun(); return(true); } else { Reload(); } } } return(false); }