public void ExecuteRangedAttack()
{
Vector3 TargetingPoint;
if (gtarg.name=="_Gronk")
{//Try and hit the player
TargetingPoint=GameWorldController.instance.playerUW.playerCam.transform.position;
}
else
{//Trying to hit an object
TargetingPoint=gtarg.GetComponent<ObjectInteraction>().GetImpactPoint();//Aims for the objects impact point
}
Vector3 TargetingVector = (TargetingPoint-NPC_Launcher.transform.position).normalized*adj;
//Ray ray= new Ray(NPC_Launcher.transform.position,TargetingPoint-NPC_Launcher.transform.position);
Ray ray= new Ray(NPC_Launcher.transform.position,TargetingVector);
RaycastHit hit = new RaycastHit();
float dropRange=0.5f;
if (!Physics.Raycast(ray,out hit,dropRange))
{///Checks No object interferes with the launch
float force = testforce;
GameObject launchedItem ;
launchedItem= ObjectInteraction.CreateNewObject(16).gameObject;
//launchedItem = Instantiate(currentAmmo.gameObject);
launchedItem.name="launched_missile_" +GameWorldController.instance.playerUW.PlayerMagic.SummonCount++;
launchedItem.GetComponent<ObjectInteraction>().Link=1;//Only 1
launchedItem.transform.parent=GameWorldController.instance.LevelMarker();
launchedItem.GetComponent<ObjectInteraction>().PickedUp=false; //Back in the real world
launchedItem.transform.position=ray.GetPoint(dropRange-0.1f);//GameWorldController.instance.playerUW.transform.position;
GameWorldController.UnFreezeMovement(launchedItem);
Vector3 ThrowDir = TargetingVector;//ray.GetPoint(dropRange) - ray.origin;
///Apply the force along the direction of the ray that the player has targetted along.
launchedItem.GetComponent<Rigidbody>().AddForce(ThrowDir*force);
GameObject myObjChild = new GameObject(launchedItem.name + "_damage");
myObjChild.transform.position =launchedItem.transform.position;
myObjChild.transform.parent =launchedItem.transform;
///Appends ProjectileDamage to the projectile to act as the damage delivery method.
ProjectileDamage pd= myObjChild.AddComponent<ProjectileDamage>();
pd.Source=this.gameObject;
pd.Damage=10;
Ammo--;
}
}