private void ShootLaser() { Collider[] colls = Physics.OverlapSphere(transform.position, laserLength, LayerMask.GetMask("Alley")); float closestDist = float.MaxValue; target = null; foreach (var item in colls) { Mob itemMob = item.GetComponent <Mob>(); if (itemMob) { Vector3 subVec = item.transform.position - transform.position; float sqrDist = subVec.sqrMagnitude; if (sqrDist <= closestDist) { closestDist = sqrDist; target = itemMob; } } } if (target) { AnimEventBehavior laserStartBehavior = ScriptableObject.CreateInstance <AnimEventBehavior>(); laserStartBehavior.Init(BehaviorPriority.Skill, new AnimEventBData("laser", mainSoundPlayer, "LaserCharge", 1.0f), laserChargeTime); fsm.DirectAddBehavior(laserStartBehavior); LaserBehavior laserStayBehavior = ScriptableObject.CreateInstance <LaserBehavior>(); laserStayBehavior.Init(BehaviorPriority.Skill, new LaserBData(target, mainSoundPlayer, "Laser", 0.25f), laserDuration); fsm.DirectAddBehavior(laserStayBehavior); IdleBehavior idleBehavior = ScriptableObject.CreateInstance <IdleBehavior>(); idleBehavior.Init(BehaviorPriority.Basic, null, 2.5f); fsm.DirectAddBehavior(idleBehavior); } }
public void SpawnLaser(Vector3 p, Vector3 dir) { //Debug.Assert(CanSpawn()); laserOverheat++; GameObject e = GameObject.Instantiate(laser); // as GameObject; LaserBehavior Laser = e.GetComponent <LaserBehavior>(); // Shows how to get the script from GameObject if (null != Laser) { e.transform.position = p; e.transform.up = dir; } mSpawnLaserAt = Time.realtimeSinceStartup; }