public override void Activate(Vector3 startPosition, Quaternion startRotation, Collider2D col = null) { // Instantiate bullet type at given position with given rotation. GameObject projectile = Instantiate(ProjectileType, startPosition, startRotation); // Grab projectile script (and optionally cast to specific projectile type). LaserProjectile projectileScript = (LaserProjectile)projectile.GetComponent <BehaviourProjectile>(); // Set delegate to this behaviour's trigger event. projectileScript.Initialize(OnTriggered, PlayerID, Settings, Stats); }
public static LaserProjectile Create(Vector2 spawnPosition, Vector2 targetPosition) { Transform pfProjectile = Resources.Load <Transform>("pfLaserProjectile"); Transform projectileTransform = Instantiate(pfProjectile, spawnPosition, Quaternion.identity); LaserProjectile projectile = projectileTransform.GetComponent <LaserProjectile>(); projectile.SetTargetPosition(targetPosition); projectile.SetDirection(spawnPosition, targetPosition); return(projectile); }
private void ToAttack(KeyCode attackKey) { if (CanAttack && Input.GetKey(attackKey)) { _shootCooldown = _shotingRate; LaserProjectile newLaserProjectile = Instantiate(_laserProjectile, _playerShip.transform.position, transform.rotation); newLaserProjectile.Parent = _playerShip.gameObject; newLaserProjectile.Direction = transform.up; } }
private void ToAttack() { if (_target != null) { if (CanAttack && Vector3.Distance(_target.position, transform.position) < 8.0f) { _shootCooldown = _shotingRate; LaserProjectile newLaserProjectile = Instantiate(_laserProjectile, transform.position, transform.rotation); newLaserProjectile.Parent = gameObject; newLaserProjectile.Direction = transform.up; } } }
void OnTriggerEnter(Collider col) { Debug.Log("HIT SOMETHING"); if (col.tag == "Enemy") { col.GetComponent <Animator>().SetBool("isAlive", false); PlayHit(); Destroy(col.gameObject, 2.0f); } if (col.tag == "Laser") { Debug.Log("Doot"); LaserProjectile l = col.GetComponent <LaserProjectile>(); l.Reflect(); } }
public void shootLaser() { Vector2 start = Vector2.Zero; switch (curDirection) { case Direction.Left: start = new Vector2(-38, 0); break; case Direction.Right: start = new Vector2(38, 0); break; case Direction.Forward: start = new Vector2(0, 10); break; case Direction.Back: start = new Vector2(0, -38); break; } LaserProjectile proj = new LaserProjectile(this, start, position + fourWayDirection() * SPECIALRANGE, SPECIALDAMAGE, SPECIALDURATION); proj.setTexture(new AnimatedTexture(BASETEX + "glass-laser")); }
private void ProcessFiring() { shootTimer -= Time.deltaTime; laserTimer -= Time.deltaTime; if (Input.GetMouseButton(0) && shootTimer <= 0 && moonChunkAmount > 0) { shootTimer = shootingTimerMax; ShootGuns(); AmmoUI.Instance.SetAmmoText(moonChunkAmount); SoundManager.Instance.PlaySound(SoundManager.Sounds.ShotgunShot); } if (Input.GetMouseButton(1) && laserTimer <= 0) { laserTimer = laserTimerMax; LaserProjectile.Create(laserTransform.position, camera.ScreenToWorldPoint(Input.mousePosition)); SoundManager.Instance.PlaySound(SoundManager.Sounds.LaserShot); } }
public override bool buttonUP() { float heldTime = Time.time - timeStarted; if (heldTime <= minimumHeldTime) { startedHold = false; return(false); } if (thisView != null) { thisView.RPC("buttonUpBy", PhotonTargets.All, null); } else { buttonUpBy(); } //Projectile Stuff GameObject g = projectilePooler.getObject(); //Set Transform to this and reset Timer g.transform.position = laserStart.position; LaserProjectile c = g.GetComponent <LaserProjectile>(); c.thisPooler = this; c.render(shoot(laserStart.position, Camera.main.transform.forward, 0, new List <Vector3>() { laserStart.TransformPoint(Vector3.zero) }, c.lineRenderer), itemReset); return(false); }
public void CreateProjectile(ProjectileTypes type, Vector2 position, Vector2 velocityOffset, float rotation, int projectileID, ICanFire firingObj, float charge, byte firingWeaponSlot) { IProjectile proj = null; Vector2 projectileVelocity = new Vector2(velocityOffset.X / 1000f + (float)(Math.Sin(rotation)) * _flyweights[type].BaseSpeed / 1000f, velocityOffset.Y / 1000f - (float)(Math.Cos(rotation)) * _flyweights[type].BaseSpeed / 1000f); if (firingObj is Turret) { proj = new TurretLaser(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, ((Turret)firingObj).TurretType, _world); proj.BodyData = new ProjectileBodyDataObject(BodyTypes.Projectile, projectileID, firingObj, proj); } else { switch (type) { case ProjectileTypes.Laser: proj = new LaserProjectile(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, _world); break; case ProjectileTypes.LaserWave: proj = new LaserWaveProjectile(_collisionManager, _particleManager, projectileVelocity, _spriteBatch, projectileID, firingWeaponSlot, _world); break; case ProjectileTypes.PlasmaCannon: proj = new PlasmaCannonProjectile(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, _world, charge); break; case ProjectileTypes.BC_Laser: proj = new BC_LaserProjectile(_collisionManager, _spriteBatch, projectileID, firingWeaponSlot, _world); break; case ProjectileTypes.GravityBomb: proj = new GravityBombProjectile(_collisionManager, _particleManager, projectileVelocity, firingObj, _world, projectileID, firingWeaponSlot, position); break; case ProjectileTypes.MineSplash: proj = new MineSplash(position, _world, _collisionManager, projectileID, firingWeaponSlot); break; default: ConsoleManager.WriteLine("ERROR: ProjectileType " + type + " not implemented in ProjectileManager.CreateProjectile().", ConsoleMessageType.Error); break; } // Proj could be null here, but it should be an easy catch if we forget to add a switch case and it breaks proj.BodyData = new ProjectileBodyDataObject(BodyTypes.Projectile, projectileID, firingObj, proj); } proj.LinearVelocity = projectileVelocity; proj.Rotation = rotation; proj.Position = position; proj.Id = projectileID; _projectileList.Add(proj); }
void Fireit() { mylaser = Instantiate(laser, transform.position, Quaternion.identity).GetComponent <LaserProjectile>(); mylaser.target = GameObject.FindGameObjectWithTag("Player").transform.position; mylaser.GetVeloc(); }
// Update is called once per frame void Update() { HpLeft = Hp.CheckHealth(); if (HpLeft <= 0) { BeforeDestroy(); Destroy(gameObject); } TargetCount = TargetableObjects.Count; if (Target == null) { SM.DesiredState = FSMStateIDs.StateIds.FSM_Idle; // If the list isn't empty if (TargetableObjects.Count > 0) { // If its an aggressive AI, Find player if (IsAggressive && TargetableObjects.Contains(Player)) { Target = Player; } else if (IsAggressive) { foreach (GameObject G in TargetableObjects) { if (TargetableObjects.Count <= 0) { break; } if (G != null && G.tag == "NeutralAI") { Target = G; break; } } } // If no player or not aggressive Find another object if (!IsAggressive) { foreach (GameObject G in TargetableObjects) { if (TargetableObjects.Count <= 0) { break; } if (G != null && (G.tag == "Astroid" || G.tag == "Comet")) { Target = G; break; } } string TargetTag = ""; if (Target != null) { TargetTag = Target.tag; } if (TargetTag == "Player" || TargetTag == "AgressiveAi") { Target = null; } } } SM.Target = Target; if (Target == null) { SM.DesiredState = FSMStateIDs.StateIds.FSM_Idle; } else { TargetTransform = Target.transform; } } else { if (TargetTransform == null) { Target = null; SM.DesiredState = FSMStateIDs.StateIds.FSM_Idle; } else { Direction = TargetTransform.position - transform.position; Distance = Direction.magnitude; if (Distance >= FollowRange) { SM.DesiredState = FSMStateIDs.StateIds.FSM_Chase; } else if (Distance <= FireRange) { SM.DesiredState = FSMStateIDs.StateIds.FSM_IdleChase; } if (Distance <= FollowRange) { ROFTimer -= Time.deltaTime; if (ROFTimer <= 0) { LaserProjectile temp = Instantiate(LaserPrefab, FirePosition1); temp.SetWhoFiredMe(Hp); temp.transform.parent = null; temp.SetDamage(LaserDamage); LaserProjectile temp2 = Instantiate(LaserPrefab, FirePosition2); temp2.SetWhoFiredMe(Hp); temp2.transform.parent = null; temp2.SetDamage(LaserDamage); ROFTimer = 1 / RateOfFire; } } } } if (Hp.WhoHitMe() != null && Hp.WhoHitMe().gameObject != gameObject) { Target = Hp.WhoHitMe().gameObject; } }