Question by
Lolerooz · Dec 29, 2016 at 06:24 AM ·
2dif-statementsiskinematic
Cant exit IsKinematic
Hey guys! I set up a script so that when i pick up a gun, sword, whatever, when I click the RMB, the obejct is dropped, moves the direction the muse is pointing at and then, after a certain distance, it stops, however, when the script is executed, the gun just drifts away, apparently, the script doesnt excecute all the way
Here is the script:
using UnityEngine;
using System.Collections;
public class ThrowWeapon : MonoBehaviour {
EnemyAttacked attacked;
float timer = 2.0f;
Vector3 direction;
Rigidbody2D rid;
GameObject player;
// Use this for initialization
void Start () {
player = GameObject.FindGameObjectWithTag ("Player");
rid = this.GetComponent<Rigidbody2D> ();
rid.AddForce (direction*40);
}
// Update is called once per frame
void Update () {
transform.rotation = Quaternion.Slerp(this.transform.rotation,new Quaternion(this.transform.rotation.x,this.transform.rotation.y,this.transform.rotation.z-1,this.transform.rotation.w), Time.deltaTime * 10);
timer -= Time.deltaTime;
if(timer<=0)
{
rid.isKinematic = true;
Debug.Log("ItWorks");
Destroy (this);
}
}
}
Thanks in advance!
Comment
Your answer
Follow this Question
Related Questions
Advise on scripting text adventure 1 Answer
Mobile screen resolution 0 Answers
Get a constant Speed 0 Answers
How to make a gameobject only visible through another gameobject in 2D? 0 Answers
Setting 2D Screen Boundaires 1 Answer