예제 #1
0
 // Use this for initialization
 void Start()
 {
     rb = GetComponent<Rigidbody> ();
     rb.AddForce ((Vector3.up * upVelocity) + (Vector3.left * Random.Range (-pushAmt, pushAmt)) + (Vector3.forward * Random.Range (-pushAmt, pushAmt)));
     rb.AddTorque (Vector3.up * Random.Range (-turnAmt, turnAmt));
     rb.AddTorque (Vector3.left * Random.Range (-turnAmt, turnAmt));
 }
예제 #2
0
 void Start()
 {
     rb = GetComponent<Rigidbody>();
     rb.maxAngularVelocity = 1000;
     rb.AddTorque(0, speed, 0);
     StartCoroutine(PerdaVelocidade());
 }
예제 #3
0
 void Start()
 {
     if(useRigidbody){
         rigidbody = GetComponent<Rigidbody>();
         rigidbody.AddTorque(transform.up * torque * (int)turnDirection);
     }
 }
예제 #4
0
 static public int AddTorque(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 5)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             UnityEngine.ForceMode a4;
             checkEnum(l, 5, out a4);
             self.AddTorque(a1, a2, a3, a4);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             self.AddTorque(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode a2;
             checkEnum(l, 3, out a2);
             self.AddTorque(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 2)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             self.AddTorque(a1);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #5
0
 public void applyAngularForce(Rigidbody toBody, Vector3 desiredTorque, bool relative)
 {
     if(relative) {
         toBody.AddRelativeTorque(desiredTorque, this.angularForceMode);
     }
     else {
         toBody.AddTorque(desiredTorque, this.angularForceMode);
     }
 }
예제 #6
0
 static public int AddTorque(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(UnityEngine.Vector3), typeof(UnityEngine.ForceMode)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode a2;
             checkEnum(l, 3, out a2);
             self.AddTorque(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(UnityEngine.Vector3)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             self.AddTorque(a1);
             return(0);
         }
         else if (matchType(l, 2, typeof(System.Single), typeof(System.Single), typeof(System.Single)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             self.AddTorque(a1, a2, a3);
             return(0);
         }
         else if (matchType(l, 2, typeof(System.Single), typeof(System.Single), typeof(System.Single), typeof(UnityEngine.ForceMode)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             UnityEngine.ForceMode a4;
             checkEnum(l, 5, out a4);
             self.AddTorque(a1, a2, a3, a4);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
예제 #7
0
    void Shoot()
    {
		var rotation = Quaternion.AngleAxis (90f, Vector3.forward);
		GameObject NuevaBala = Instantiate(balloon, source.transform.position, rotation) as GameObject;
        NuevaBala.transform.LookAt(MousePos);
        rb = NuevaBala.GetComponent<Rigidbody>();
        rb.AddForce(    torreta.transform.forward * ShootForce);
		rb.AddTorque (Vector3.right * ShootForce);
        Destroy(NuevaBala, 5);

    }
예제 #8
0
    static int AddTorque(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                obj.AddTorque(arg0);
                return(0);
            }
            else if (count == 3)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.ForceMode arg1 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 3, typeof(UnityEngine.ForceMode));
                obj.AddTorque(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                obj.AddTorque(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 5)
            {
                UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                UnityEngine.ForceMode arg3 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 5, typeof(UnityEngine.ForceMode));
                obj.AddTorque(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddTorque"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody>();

        //rbc = GameObject.Find("redbloodCell");
        // add random torque to the RBC so that it is spinning slightly
        float tX = Random.Range(-5.0f, 5.0f);
        float tY = Random.Range(-5.0f, 5.0f);
        float tZ = Random.Range(-5.0f, 5.0f);
        Vector3 newTorque = new Vector3 (tX, tY, tZ);
        rb.AddTorque(newTorque);

        Destroy(gameObject, 20);
    }
    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody>();

        wbc = GameObject.Find("whiteBloodCell");
        //returningPoint = GameObject.FindGameObjectWithTag("returningPoint");
        //forceAreaReturn = GameObject.FindGameObjectWithTag("forceAreaReturn");

        // add random torque to the WBC so that it is spinning slightly
        float tX = Random.Range(-5.0f, 5.0f);
        float tY = Random.Range(-5.0f, 5.0f);
        float tZ = Random.Range(-5.0f, 5.0f);
        Vector3 newTorque = new Vector3(tX, tY, tZ);
        rb.AddTorque(newTorque);
    }
        public override void OnFixedUpdate()
        {
            if (rigidbody != null)
            {
                switch (space)
                {
                case Space.World:
                    rigidbody.AddTorque(owner.GetValue(torque), forceMode);
                    break;

                case Space.Self:
                    rigidbody.AddRelativeTorque(owner.GetValue(torque), forceMode);
                    break;
                }
            }
            Finish();
        }
예제 #12
0
    // Use this for initialization
    void Start()
    {
        if (directionRight)
        {
            direction = new Vector3(-1.0f, 1.0f, 0.0f);
            offset = new Vector3(1.0f, 2.0f, 0.0f);
        } else
        {
            direction = new Vector3(1.0f, 1.0f, 0.0f);
            offset = new Vector3(-2.0f, 2.0f, 0.0f);
        }

        gameObject.transform.position = player.gameObject.transform.position + offset;

        rigidBody = GetComponent<Rigidbody>();
        rigidBody.AddForce(direction * thrust, ForceMode.Impulse);
        rigidBody.AddTorque(new Vector3(0, 0, rotation), ForceMode.Impulse);
    }
예제 #13
0
    // Use this for initialization
    void Start()
    {
        myRigidBody = GetComponent<Rigidbody>();
        myNetworkView = GetComponent<NetworkView>();
        myNetworkManager = Camera.main.GetComponent<NetworkManager>();

        myRigidBody.maxAngularVelocity = topAngularSpeed;
        myRigidBody.AddRelativeForce(fireForce * Vector3.forward);
        myRigidBody.AddRelativeForce(Random.Range(-fireRandomForce, fireRandomForce) * Vector3.right);
        myRigidBody.AddTorque(Random.Range(-fireRandomTorque, fireRandomTorque) * Vector3.up);
        transform.Rotate(Vector3.up, Random.Range(-fireRandomAngle, fireRandomAngle));

        if (!myNetworkManager.multiplayerEnabled || myNetworkView.isMine)
        {
            myTarget = new GameObject("Target");
            myTarget.transform.position = Camera.main.GetComponent<ControlsHandler>().mousePosition;
            myTarget.transform.parent = Camera.main.GetComponent<ControlsHandler>().target;
        }
    }
예제 #14
0
    void Update()
    {
        //If the player health is <= 0, destroy the player
        if(playerHealth <= 0.0f){
            if(playerIsAlive){ //Test to see if the player health has just crossed below 0.0

                centerMessageController.UpdateCenterMessage("Press Tab to Restart");
                centerMessageController.FlashCenterMessageAfterSeconds(0.5f);

                playerWeaponChange = playerGO.GetComponent<PlayerWeaponChange>();

                dropPoint = playerWeaponChange.dropPoint.position;
                //Test to see if the dropPoint is being blocked by an obstacle...
                RaycastHit wallHit;
                if(Physics.Raycast (playerWeaponChange.transform.position, (dropPoint - playerWeaponChange.transform.position), out wallHit, (dropPoint - playerWeaponChange.transform.position).magnitude, 1 << LayerMask.NameToLayer("Environment_Collision"))){
                    dropPoint = playerWeaponChange.transform.position+(wallHit.point-playerWeaponChange.transform.position)*0.8f;
                }

                usableWeapons = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<UsableWeapons>();

                if(playerWeaponChange.hasPrimaryWeap == true){
                    string equippedWeaponName = playerWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                    int equippedWeaponIndex = usableWeapons.primaryUsableWeapons.IndexOf (equippedWeaponName);
                    dropWeapon = Instantiate(usableWeapons.worldPrimaryUsableWeapons [equippedWeaponIndex], dropPoint, playerWeaponChange.primarySpawnpoint.rotation) as Rigidbody;
                    dropWeapon.AddForce(playerGO.GetComponent<Rigidbody>().velocity*playerWeaponChange.dropForce);
                    dropWeapon.AddTorque (transform.up*playerWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                    dropWeapon.GetComponent<weaponIndex>().ammoCount = playerWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                }
                if(playerWeaponChange.hasSecondaryWeap == true){
                    string equippedWeaponName = playerWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                    int equippedWeaponIndex = usableWeapons.secondaryUsableWeapons.IndexOf (equippedWeaponName);
                    dropWeapon = Instantiate(usableWeapons.worldSecondaryUsableWeapons [equippedWeaponIndex], dropPoint, playerWeaponChange.secondarySpawnpoint.rotation) as Rigidbody;
                    dropWeapon.AddForce(playerGO.GetComponent<Rigidbody>().velocity*playerWeaponChange.dropForce);
                    dropWeapon.AddTorque (transform.up*playerWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                    dropWeapon.GetComponent<weaponIndex>().ammoCount = playerWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                }
                deadBody = Instantiate (deadPlayer[damageTypeIndex], playerGO.transform.position, playerWeaponChange.primarySpawnpoint.rotation) as Rigidbody;

                //Check for helmet...
                if(deadBody.GetComponent<Animator>()){
                    Animator[] anims = playerGO.GetComponentsInChildren<Animator> ();
                    Animator deadBodyAnim = deadBody.GetComponent<Animator>();
                    foreach (Animator a in anims) {
                        AnimatorControllerParameter[] acps = a.parameters;
                        foreach (AnimatorControllerParameter acp in acps){
                            if(acp.name == "helmetEquipped"){
                                bool currentValue = a.GetBool ("helmetEquipped");
                                deadBodyAnim.SetBool ("helmetEquipped", currentValue);
                                break;
                            }
                        }
                    }
                    AnimatorControllerParameter[] deadBodyAcp = deadBodyAnim.parameters;
                    AnimatorControllerParameterType paramType = AnimatorControllerParameterType.Bool;
                    int randomIndex = 0;
                    while (paramType != AnimatorControllerParameterType.Trigger){
                        randomIndex = Random.Range (0, deadBodyAcp.Length); //Random.Range is exclusive for the 2nd value
                        paramType = deadBodyAcp[randomIndex].type;
                    }
                    deadBodyAnim.SetTrigger (deadBodyAcp [randomIndex].name);
                }
                //End check for helmet

                if(damageForce != Vector3.zero){
                    deadBody.AddForce (damageForce);
                }
                if(explosionForce != 0.0f){
                    //deadBody.AddExplosionForce(explosionForce, explosionLocation, explosionRadius);
                    deadBody.AddForce (explosionForce*((playerGO.transform.position - explosionLocation).normalized));
                }
            }
            playerIsAlive = false;
            Destroy(playerGO);

        }
    }
예제 #15
0
 public void FixedUpdate()
 {
     RBody.AddTorque(BallTorgueVector.normalized * ForceScale, UnityEngine.ForceMode.Impulse);
 }
예제 #16
0
    /// <summary>
    /// Rotates the rigidbody.
    /// </summary>
    /// <returns>
    /// True if rigid body is successfully rotated.
    /// </returns>
    /// <param name='id'>
    /// Touch id.
    /// </param>
    /// <param name='torqueScalar'>
    /// Scalar value applied to torque calculation.
    /// </param>
    /// <param name='rigidbody'>
    /// Rigid body to rotate.
    /// </param>
    public static bool RotateRigidbody(int id, float torqueScalar, Rigidbody rigidbody)
    {
        bool success = false;

        Vector3 axis;

        float torque;

        if (TouchManager.RotationAxisTorque(id, torqueScalar, out axis, out torque))
        {

            rigidbody.AddTorque(axis * torque);

            success = true;
        }

        return success;
    }
예제 #17
0
    // Update is called once per frame
    void Update()
    {
        //update text and timers
        textOutput.text = count.ToString();
        timeSinceClick += Time.deltaTime;

        //check for object destruction
        if (selected)
        {
            if (selectedObj == null)
            {
                selected = false;
                return;
            }
            else
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                selectedObj.transform.position = ray.GetPoint(distToMaintain);
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (!selected)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits = Physics.RaycastAll(ray);

                foreach (RaycastHit hit in hits)
                {
                    if (hit.collider.gameObject.tag == "Resource")
                    {
                        selected = true;
                        selectedObj = hit.collider.gameObject;
                        selectedRigidbody = selectedObj.GetComponent<Rigidbody>();
                        selectedRigidbody.useGravity = false;
                        selectedRigidbody.AddTorque(selectedObj.transform.position.normalized * 7);
                        distToMaintain = Vector3.Distance(selectedObj.transform.position, Camera.main.transform.position);

                        break;
                    }
                }
            }
        }
        else
        {
            if (selected)
            {
                selectedRigidbody.useGravity = true;
                selectedRigidbody.AddForce(Vector3.down * fallForce);

                if (timeSinceClick <= clickTime)
                {
                    Destroy(selectedObj);
                    count++;
                }
            }

            selected = false;
            timeSinceClick = 0.0f;
        }
    }
예제 #18
0
	/// <summary>
	/// 
	/// </summary>
	protected virtual void Start()
	{

		m_Transform = transform;
		m_Rigidbody = rigidbody;
		m_Audio = audio;

		if (Camera.main != null)
			m_CameraMainTransform = Camera.main.transform;

		// set the main collider of this gameobject to be a trigger
		collider.isTrigger = true;

		// some default audio settings
		m_Audio.clip = PickupSound;
		m_Audio.playOnAwake = false;
		m_Audio.minDistance = 3;
		m_Audio.maxDistance = 150;
		m_Audio.rolloffMode = AudioRolloffMode.Linear;
		m_Audio.dopplerLevel = 0.0f;

		// store the initial position
		m_SpawnPosition = m_Transform.position;
		m_SpawnScale = m_Transform.localScale;
		RespawnScaleUpDuration = (m_Rigidbody == null) ? Mathf.Abs(RespawnScaleUpDuration) : 0.0f;

		// give bob a random start offset if value is not set
		if (BobOffset == -1.0f)
			BobOffset = Random.value;

		if (RecipientTags.Count == 0)
			RecipientTags.Add("Player");

		if (RemoveDuration != 0.0f)
			vp_Timer.In(RemoveDuration, Remove);

		if (m_Rigidbody != null)
		{
			if(RigidbodyForce != Vector3.zero)
				m_Rigidbody.AddForce(RigidbodyForce, ForceMode.Impulse);
			if(RigidbodySpin != 0.0f)
				m_Rigidbody.AddTorque(Random.rotation.eulerAngles * RigidbodySpin);
		}
	}
예제 #19
0
 public void Launch(Rigidbody toLaunch)
 {
     toLaunch.isKinematic = false;
     toLaunch.AddForce (forceToPush * forceMult);
     toLaunch.AddTorque (forceToPush * forceMult);
     toLaunch.gameObject.GetComponent<Animator> ().SetTrigger ("shrink");
 }
예제 #20
0
 public static void SetRandomTorque(Rigidbody rb, float maxTorque)
 {
     Vector3 randomTorque = maxTorque * Random.insideUnitSphere;
     rb.angularVelocity = Vector3.zero;
     rb.AddTorque(randomTorque);
 }
예제 #21
0
    void Update()
    {
        facingDirection = script.GetFacingDirection ();

        // Throw Shuriken left or right
        if (amountUsed < 4) {
            if (Input.GetKeyDown (KeyCode.I)) {
                Clone = Instantiate (ShurikenPrefab, new Vector3 (spawnThrow.transform.position.x, spawnThrow.transform.position.y, -3.0f),
                                     	  Quaternion.identity) as Rigidbody;
                textObject = Instantiate (TextControlPrefab,
                                          new Vector3 (Clone.transform.position.x - 0.414f, Clone.transform.position.y + 0.352f, -3.0f),
                                          Quaternion.identity) as GameObject;

                // get first open slot
                for (int i = 0; i < Max; i++) {
                    if (shurikens [i] == null) {
                        shurikens [i] = Clone.transform;

                        textControl [i] = textObject.GetComponent<TextMesh> ();     // get the TextMesh
                        textControl [i].text = "O HOLD O";    // set initial so compiler doesnt complain
                        textPositions [i] = textObject.GetComponent<Transform> ();  // get its position

                        teleportBlast [i] = Clone.GetComponent<ParticleSystem> ();  // get its particle system

                        shurikenScripts [i] = Clone.GetComponent<ShurikenController> ();  // get its script
                        shurikenScripts [i].SetPlaced (false);

                        // Assign it the appropriate tag
                        if (i == 0)
                            Clone.gameObject.tag = "Shuriken0";
                        else if (i == 1)
                            Clone.gameObject.tag = "Shuriken1";
                        else if (i == 2)
                            Clone.gameObject.tag = "Shuriken2";
                        else if (i == 3)
                            Clone.gameObject.tag = "Shuriken3";

                        break; // found empty slot
                    }
                }
                if (facingDirection == Vector2.right) {  			// Throw to the right
                    Clone.AddForce (speed * new Vector3 (1.0f, 0.0f, 0.0f));
                    Clone.AddTorque (new Vector3 (0, 0, -turnSpeed));
                } else {    										// Throw to the left
                    Clone.AddForce (speed * new Vector3 (-1.0f, 0.0f, 0.0f));
                    Clone.AddTorque (new Vector3 (0, 0, turnSpeed));
                }
                amountUsed++;
            }
            // Place Shuriken at feet
            else if (Input.GetKeyDown (KeyCode.J)) {
                Clone = Instantiate (ShurikenPrefab, new Vector3 (spawnPlace.transform.position.x, spawnPlace.transform.position.y, -3.0f),
                                     	  Quaternion.identity) as Rigidbody;
                textObject = Instantiate (TextControlPrefab,
                                          new Vector3 (Clone.transform.position.x - 0.414f, Clone.transform.position.y + 0.352f, -3.0f),
                                          Quaternion.identity) as GameObject;

                // get first open slot
                for (int i = 0; i < Max; i++) {
                    if (shurikens [i] == null) {
                        shurikens [i] = Clone.transform;

                        textControl [i] = textObject.GetComponent<TextMesh> ();     // get the TextMesh
                        textControl [i].text = "O HOLD O";    // set initial so compiler doesnt complain
                        textPositions [i] = textObject.GetComponent<Transform> ();  // get its position

                        teleportBlast [i] = Clone.GetComponent<ParticleSystem> ();  // get its particle system

                        shurikenScripts [i] = Clone.GetComponent<ShurikenController> ();  // get its script
                        shurikenScripts [i].SetPlaced (true);   // this shuriken does not move

                        // Assign it the appropriate tag
                        if (i == 0)
                            Clone.gameObject.tag = "Shuriken0";
                        else if (i == 1)
                            Clone.gameObject.tag = "Shuriken1";
                        else if (i == 2)
                            Clone.gameObject.tag = "Shuriken2";
                        else if (i == 3)
                            Clone.gameObject.tag = "Shuriken3";

                        break; // found empty slot
                    }
                }
                amountUsed++;
            }
        }

        // update Text positions so they allign with shurikens
        for (int i = 0; i < Max; i++)
            if (shurikens [i] != null) {
                textPositions [i].position = new Vector3 (shurikens [i].position.x - 0.414f, shurikens [i].position.y + 0.352f, -3.0f);

                // is has parent then position it above it
                if (shurikens [i].parent != null)
                    textPositions [i].position += new Vector3 (0.0f, 1.0f, 0.0f);

                // if Enemy on Shuriken Position it below
                if (shurikenScripts [i].GetEnemyOnPlaced () != null)
                    textPositions [i].position -= new Vector3 (0.0f, 0.75f, 0.0f);
            }

        // When user holds down the O key alter text
        if (Input.GetKey (KeyCode.O) && !Input.GetKey (KeyCode.K)) {
            Time.timeScale = 0.2f;  // SLOW MOTION so player has time to choose

            // set controls Text
            for (int i = 0; i < Max; i++) {
                if (shurikens [i] != null)
                if (i == 0)
                    textControl [0].text = "A PRESS A";
                else if (i == 1)
                    textControl [1].text = "S PRESS S";
                else if (i == 2)
                    textControl [2].text = "D PRESS D";
                else if (i == 3)
                    textControl [3].text = "W PRESS W";
            }

            // Teleport the player to shuriken and play the effect
            if (Input.GetKeyDown (KeyCode.A) && shurikens [0] != null) {   		  // 1st shuriken
                Player.transform.position = shurikens [0].position;
                teleportBlast [0].Play (false);
            } else if (Input.GetKeyDown (KeyCode.S) && shurikens [1] != null) {    // 2nd shuriken
                Player.transform.position = shurikens [1].position;
                teleportBlast [1].Play (false);
            } else if (Input.GetKeyDown (KeyCode.D) && shurikens [2] != null) {    // 3rd shuriken
                Player.transform.position = shurikens [2].position;
                teleportBlast [2].Play (false);
            } else if (Input.GetKeyDown (KeyCode.W) && shurikens [3] != null) {    // 4th shuriken
                Player.transform.position = shurikens [3].position;
                teleportBlast [3].Play (false);
            }
        }

        // alter controls Text for shurikens with enemyOnPlaced or with a parent --> so player knows it has soemthing to teleport
        if (!Input.GetKey (KeyCode.O) && !Input.GetKey (KeyCode.K))
            for (int i = 0; i < Max; i++) {
                if (shurikens [i] != null)
                if (shurikenScripts [i].GetEnemyOnPlaced () != null || shurikens [i].parent != null)
                    textControl [i].text = "O HOLD O\nK HOLD K";    // sets if shuriken has something to teleport
                else
                    textControl [i].text = "O HOLD O";    // set back
            }

        // When user holds down K key can teleport enemy from one shuriken to another
        if (Input.GetKey (KeyCode.K) && !Input.GetKey (KeyCode.O)) {
            Time.timeScale = 0.2f;  // SLOW MOTION so player has time to choose

            // set text on those with something to teleport
            for (int i = 0; i < Max; i++) {
                if (shurikens [i] != null && (shurikenScripts [i].GetEnemyOnPlaced () != null || shurikens [i].parent != null))
                if (i == 0)
                    textControl [0].text = "A TELEPORT A";
                else if (i == 1)
                    textControl [1].text = "S TELEPORT S";
                else if (i == 2)
                    textControl [2].text = "D TELEPORT D";
                else if (i == 3)
                    textControl [3].text = "W TELEPORT W";
            }

            // Whats getting teleported
            if (Input.GetKeyDown (KeyCode.A) && isPressed [1] == false && isPressed [2] == false && isPressed [3] == false)
                isPressed [0] = true;
            else if (Input.GetKeyDown (KeyCode.S) && isPressed [0] == false && isPressed [2] == false && isPressed [3] == false)
                isPressed [1] = true;
            else if (Input.GetKeyDown (KeyCode.D) && isPressed [0] == false && isPressed [1] == false && isPressed [3] == false)
                isPressed [2] = true;
            else if (Input.GetKeyDown (KeyCode.W) && isPressed [0] == false && isPressed [1] == false && isPressed [2] == false)
                isPressed [3] = true;

            // TELEPORTING A
            if (isPressed [0] && shurikens [0] != null && (shurikenScripts [0].GetEnemyOnPlaced () != null || shurikens [0].parent != null)) {
                // Display new text, where can teleport to
                if (shurikens [1] != null)
                    textControl [1].text = "S TARGET TARGET S";
                if (shurikens [2] != null)
                    textControl [2].text = "D TARGET TARGET D";
                if (shurikens [3] != null)
                    textControl [3].text = "W TARGET TARGET W";

                // Where its getting teleported
                if (shurikenScripts [0].GetPlaced ()) { 	// placed shurikens
                    GameObject enemy = shurikenScripts [0].GetEnemyOnPlaced ().gameObject as GameObject;
                    // Teleport whats on shuriken to new location
                    if (Input.GetKeyDown (KeyCode.S) && shurikens [1] != null) {
                        enemy.transform.position = shurikens [1].position;
                        teleportBlast [1].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.D) && shurikens [2] != null) {
                        enemy.transform.position = shurikens [2].position;
                        teleportBlast [2].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.W) && shurikens [3] != null) {
                        enemy.transform.position = shurikens [3].position;
                        teleportBlast [3].Play (false);
                    }
                    SetLayer (enemy);
                } else {   		// mobile parented shurikens
                    // Teleport shuriken's parent to new location
                    if (Input.GetKeyDown (KeyCode.S) && shurikens [1] != null) {
                        shurikens [0].parent.position = shurikens [1].position;
                        teleportBlast [1].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (0);

                    } else if (Input.GetKeyDown (KeyCode.D) && shurikens [2] != null) {
                        shurikens [0].parent.position = shurikens [2].position;
                        teleportBlast [2].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (0);
                    } else if (Input.GetKeyDown (KeyCode.W) && shurikens [3] != null) {
                        shurikens [0].parent.position = shurikens [3].position;
                        teleportBlast [3].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (0);
                    }
                }
            }
        // TELEPORTING S
            else if (isPressed [1] && shurikens [1] != null && (shurikenScripts [1].GetEnemyOnPlaced () != null || shurikens [1].parent != null)) {
                // Display new text, where can teleport to
                if (shurikens [0] != null)
                    textControl [0].text = "A TARGET TARGET A";
                if (shurikens [2] != null)
                    textControl [2].text = "D TARGET TARGET D";
                if (shurikens [3] != null)
                    textControl [3].text = "W TARGET TARGET W";

                // Where its getting teleported
                if (shurikenScripts [1].GetPlaced ()) {   		// placed shurikens
                    GameObject enemy = shurikenScripts [1].GetEnemyOnPlaced ().gameObject as GameObject;
                    // Teleport whats on shuriken to new location
                    if (Input.GetKeyDown (KeyCode.A) && shurikens [0] != null) {
                        enemy.transform.position = shurikens [0].position;
                        teleportBlast [0].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.D) && shurikens [2] != null) {
                        enemy.transform.position = shurikens [2].position;
                        teleportBlast [2].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.W) && shurikens [3] != null) {
                        enemy.transform.position = shurikens [3].position;
                        teleportBlast [3].Play (false);
                    }
                    SetLayer (enemy);
                } else if (shurikens [1].parent != null) {  		// mobile parented shurikens
                    // Teleport shuriken's parent to new location
                    if (Input.GetKeyDown (KeyCode.A) && shurikens [0] != null) {
                        shurikens [1].parent.position = shurikens [0].position;
                        teleportBlast [0].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (1);
                    } else if (Input.GetKeyDown (KeyCode.D) && shurikens [2] != null) {
                        shurikens [1].parent.position = shurikens [2].position;
                        teleportBlast [2].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (1);
                    } else if (Input.GetKeyDown (KeyCode.W) && shurikens [3] != null) {
                        shurikens [1].parent.position = shurikens [3].position;
                        teleportBlast [3].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (1);
                    }
                }
            }
        // TELEPORTING D
            else if (isPressed [2] && shurikens [2] != null && (shurikenScripts [2].GetEnemyOnPlaced () != null || shurikens [2].parent != null)) {
                // Display new text, where can teleport to
                if (shurikens [0] != null)
                    textControl [0].text = "A TARGET TARGET A";
                if (shurikens [1] != null)
                    textControl [1].text = "S TARGET TARGET S";
                if (shurikens [3] != null)
                    textControl [3].text = "W TARGET TARGET W";

                // Where its getting teleported
                if (shurikenScripts [2].GetPlaced ()) {   		// placed shurikens
                    GameObject enemy = shurikenScripts [2].GetEnemyOnPlaced ().gameObject as GameObject;
                    // Teleport whats on shuriken to new location
                    if (Input.GetKeyDown (KeyCode.A) && shurikens [0] != null) {
                        enemy.transform.position = shurikens [0].position;
                        teleportBlast [0].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.S) && shurikens [1] != null) {
                        enemy.transform.position = shurikens [1].position;
                        teleportBlast [1].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.W) && shurikens [3] != null) {
                        enemy.transform.position = shurikens [3].position;
                        teleportBlast [3].Play (false);
                    }
                    SetLayer (enemy);
                } else if (shurikens [2].parent != null) {  		// mobile parented shurikens
                    // Teleport shuriken's parent to new location
                    if (Input.GetKeyDown (KeyCode.A) && shurikens [0] != null) {
                        shurikens [2].parent.position = shurikens [0].position;
                        teleportBlast [0].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (2);
                    } else if (Input.GetKeyDown (KeyCode.S) && shurikens [1] != null) {
                        shurikens [2].parent.position = shurikens [1].position;
                        teleportBlast [1].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (2);
                    } else if (Input.GetKeyDown (KeyCode.W) && shurikens [3] != null) {
                        shurikens [2].parent.position = shurikens [3].position;
                        teleportBlast [3].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (2);
                    }
                }
            }
        // TELEPORTING W
            else if (isPressed [3] && shurikens [3] != null && (shurikenScripts [3].GetEnemyOnPlaced () != null || shurikens [3].parent != null)) {
                // Display new text, where can teleport to
                if (shurikens [0] != null)
                    textControl [0].text = "A TARGET A";
                if (shurikens [1] != null)
                    textControl [1].text = "S TARGET S";
                if (shurikens [2] != null)
                    textControl [2].text = "D TARGET D";

                // Where its getting teleported
                if (shurikenScripts [3].GetPlaced ()) {   		// placed shurikens
                    GameObject enemy = shurikenScripts [3].GetEnemyOnPlaced ().gameObject as GameObject;
                    // Teleport whats on shuriken to new location
                    if (Input.GetKeyDown (KeyCode.A) && shurikens [0] != null) {
                        enemy.transform.position = shurikens [0].position;
                        teleportBlast [0].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.S) && shurikens [1] != null) {
                        enemy.transform.position = shurikens [1].position;
                        teleportBlast [1].Play (false);
                    } else if (Input.GetKeyDown (KeyCode.D) && shurikens [2] != null) {
                        enemy.transform.position = shurikens [2].position;
                        teleportBlast [2].Play (false);
                    }
                    SetLayer (enemy);
                } else if (shurikens [3].parent != null) {  		// mobile parented shurikens
                    // Teleport shuriken's parent to new location
                    if (Input.GetKeyDown (KeyCode.A) && shurikens [0] != null) {
                        shurikens [3].parent.position = shurikens [0].position;
                        teleportBlast [0].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (3);
                    } else if (Input.GetKeyDown (KeyCode.S) && shurikens [1] != null) {
                        shurikens [3].parent.position = shurikens [1].position;
                        teleportBlast [1].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (3);
                    } else if (Input.GetKeyDown (KeyCode.D) && shurikens [2] != null) {
                        shurikens [3].parent.position = shurikens [2].position;
                        teleportBlast [2].Play (false);

                        // can only teleport enemy once, then the shuriken gets destroyed
                        DestroyIt (3);
                    }
                }
            }
        }

        if (Input.GetKeyUp (KeyCode.O) || Input.GetKeyUp (KeyCode.K)) {
            Time.timeScale = 1.0f;    // Undo slow motion

            // set them back once user releases the O key or the K key
            for (int i = 0; i < Max; i++) {
                if (shurikens [i] != null)
                if (shurikenScripts [i].GetEnemyOnPlaced () != null || shurikens [i].parent != null)
                    textControl [i].text = "O HOLD O\nK HOLD K";    // sets if shuriken has something to teleport
                else
                    textControl [i].text = "O HOLD O";    // set back
            }

            // set bool elements to false
            for (int i = 0; i < Max; i++)
                isPressed [i] = false;
        }
    }
예제 #22
0
	// Use this for initialization
	void Start () {
		rb = GetComponent<Rigidbody>();
		rb.AddTorque(new Vector3(10f,4f,3f));
	}
예제 #23
0
    void Update()
    {
        //If the enemy health is <= 0, destroy the enemy
        if(enemyHealth <= 0.0f){
            if(enemyIsAlive){
                if(!cannotDropWeapons){
                    npcWeaponChange = gameObject.GetComponent<NonPlayerCharacterWeaponChange>();

                    dropPoint = npcWeaponChange.dropPoint.position;

                    //Test to see if the dropPoint is being blocked by an obstacle...
                    RaycastHit wallHit;
                    if(Physics.Raycast (transform.position, (dropPoint - transform.position), out wallHit, (dropPoint - transform.position).magnitude, 1 << LayerMask.NameToLayer("Environment_Collision"))){
                        dropPoint = transform.position+(wallHit.point-transform.position)*0.8f;
                    }

                    usableWeapons = gameObject.GetComponent<UsableWeapons>();
                    if(npcWeaponChange.hasPrimaryWeap == true){
                        string equippedWeaponName = npcWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                        int equippedWeaponIndex = usableWeapons.primaryUsableWeapons.IndexOf (equippedWeaponName);
                        dropWeapon = Instantiate(usableWeapons.worldPrimaryUsableWeapons [equippedWeaponIndex], dropPoint, npcWeaponChange.primarySpawnpoint.rotation) as Rigidbody;
                        dropWeapon.AddForce(GetComponent<NavMeshAgent>().velocity*npcWeaponChange.dropForce);
                        dropWeapon.AddTorque (transform.up*npcWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                        dropWeapon.GetComponent<weaponIndex>().ammoCount = npcWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                    }
                    if(npcWeaponChange.hasSecondaryWeap == true){
                        string equippedWeaponName = npcWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                        int equippedWeaponIndex = usableWeapons.secondaryUsableWeapons.IndexOf (equippedWeaponName);
                        dropWeapon = Instantiate(usableWeapons.worldSecondaryUsableWeapons [equippedWeaponIndex], dropPoint, npcWeaponChange.secondarySpawnpoint.rotation) as Rigidbody;
                        dropWeapon.AddForce(GetComponent<NavMeshAgent>().velocity*npcWeaponChange.dropForce);
                        dropWeapon.AddTorque (transform.up*npcWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                        dropWeapon.GetComponent<weaponIndex>().ammoCount = npcWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                    }
                }
                if(deadBodyRandomRotation){
                    deadBodyRotation = Quaternion.AngleAxis (Random.Range (0f, 360f),Vector3.up);
                }
                else{
                    deadBodyRotation = transform.rotation;
                }
                deadBody = Instantiate (deadEnemy[damageTypeIndex], transform.position, deadBodyRotation ) as Rigidbody;

                deadBody.transform.Rotate (Vector3.right, 90f);
                if(damageForce!= Vector3.zero){
                    deadBody.AddForce (damageForce);
                }
                if(explosionForce!= 0.0f){
                    //deadBody.AddExplosionForce (explosionForce,explosionLocation, explosionRadius);
                    deadBody.AddForce (explosionForce*((transform.position - explosionLocation).normalized));
                }

                //Pick a random spawnOnDeath from the list
                if(spawnOnDeath.Count > 0){
                    int spawnIndex = 0;
                    float randomNumber = Random.value*100.0f;
                    int spawnOptionCount = spawnOnDeath.Count;
                    float minCheck = 0.0f;
                    float maxCheck = 0.0f;
                    if(randomNumber == 0.0f){
                        spawnIndex = 0;
                    }
                    else if(randomNumber == 1.0f){
                        spawnIndex = spawnOnDeath.Count - 1;
                    }
                    else{
                        for (int i=0; i < spawnOptionCount; i++){
                            maxCheck = maxCheck + percentSpawnOnDeath[i];
                            if (randomNumber >= minCheck && randomNumber < maxCheck){
                                spawnIndex = i;
                            }
                            minCheck = maxCheck;
                        }
                    }
                    Instantiate(spawnOnDeath[spawnIndex], transform.position, spawnOnDeath[spawnIndex].transform.rotation);
                }
                if(targetGO != null){
                    (targetGO.GetComponent(scriptNameToEnable) as MonoBehaviour).enabled = true;
                }
            }
            enemyIsAlive = false;
            /*if(localSceneObjectsExist){
                if(!ignoreEnemyForSceneClearing && gameObject.tag == Tags.enemy && !localScenePersistentGameObjects.isCleared){
                    sceneFadeInOut.remainingEnemiesList.Remove(gameObject);
                    sceneFadeInOut.SceneStatusCheckDelay(true);
                }
            }*/
            if(sceneFadeInOut.remainingEnemiesList.Contains (gameObject)){
                sceneFadeInOut.remainingEnemiesList.Remove(gameObject);
                sceneFadeInOut.SceneStatusCheckDelay(true);
            }
            Destroy(gameObject);

        }
    }