The force is not being applied when I click the mouse and I can not figure out why.
// Sets the guns object
var gunActive : boolean;
var gunInHand : boolean;
var gunHoldPostion : Transform;
var inGunPickupZone : boolean;
var gunEnd : Transform;
var gunModel : GameObject;
var gunEndPost : Vector3;
var gunEndDirection : Vector3;
var zoomedIn : boolean;
var gunLine : boolean;
var sparksObject : GameObject;
var sparks : Transform;
var pokeForce : int;
var rayColor : Color;
var zoomCam : Camera;
var camSmooth : float;
var zoomCamPost : Transform;
var zoomCamPostDefault : Transform;
function Start ()
{
sparksObject.SetActive(false);
zoomedIn = false;
}
function OnTriggerEnter (col : Collider)
{
if(col.gameObject.tag == "Player")
{
inGunPickupZone = true;
Debug.Log("In Zone!");
}
}
function FixedUpdate ()
{
gunEndPost = gunEnd.position;
if(Input.GetButtonUp("Action Key") && inGunPickupZone.Equals(true))
{
gunActive = true;
}
else if(Input.GetButtonUp("Action Key"))
{
Debug.Log("Not in Pick-Up Zone");
}
}
function Update ()
{
if(gunActive.Equals(true))
{
gunModel.transform.position = gunHoldPostion.position;
gunInHand = true;
gunActive = false;
}
if(gunInHand.Equals(true))
{
gunModel.transform.position = gunHoldPostion.position;
}
// Fires red line when Priamry is active
if(gunLine.Equals(true))
{
var hit2 : RaycastHit;
var ray2 = new Ray (gunEndPost, gunEndDirection);
var forward2 : Vector3 = gunEnd.TransformDirection(Vector3.forward) * 100;
Debug.DrawRay(gunEndPost,forward2,Color.red,.01f,true);
if(Physics.Raycast(ray2, hit2))
{
Debug.Log("Red Line");
}
}
// For Primary
if(Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray = new Ray (gunEndPost, gunEndDirection);
var forward : Vector3 = gunEnd.TransformDirection(Vector3.forward) * 100;
Debug.Log("Raycast was fired");
Debug.DrawRay(gunEndPost,forward,Color.green,.25f,true);
if(Physics.Raycast(ray, hit))
{
Debug.Log("Right Before force it applied");
if(hit.rigidbody != null)
{
sparksObject.SetActive(true);
hit.rigidbody.AddForceAtPosition(ray.direction * pokeForce, hit.point);
// creates a partical effect
var particleClone = Instantiate(sparks, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
Debug.Log("Force was Applied");
}
}
}