Hey guys,
I wrote a script which move my weapon to the point I’ved set in the scene.The problem is when i pick it up I don’t want that it just move to the point I want that it moves to the point and stay with the player (sorry for bad english I hope you understand what I mean)
I’ve add the point where it moves to, to the camera in the scene.
Here’s my code :
var gegenstand :Transform;
var stopTakeWeapon = false;
var Spawn :Transform;
function takeWeapon ()
{
Debug.Log("takeweapon gestartet");
if(Vector3.Distance(transform.position,gegenstand.position)<=5){
Debug.Log("unter 5 meter");
if(Input.GetButtonDown ("e") ){
Debug.Log("e gedrückt");
gegenstand.transform.position = Spawn.position;
//gegenstand.transform.position = Vector3(0,20,50);
stopTakeWeapon = true;
}
}
}
function Update ()
{
if(stopTakeWeapon == false)
{
takeWeapon ();
}
}
Thanks for help ![]()
I dont understand what you are trying to say when you explain that you want the weapon to move. Do you want weapon sway? you want an animation for the weapon being picked up?
– ExpiredIndexCardit works with other stuff, for me. And by that I mean, calling an external function from outside OnGUI..
– thornekeyusing UnityEngine; using System; using System.Collections; public class Example : MonoBehaviour { void Update() { NotInGUI(); } //Will not work. void NotInGUI() { GUILayout.Label("Outside of GUI Function"); } //Will work. void OnGUI() { GUILayout.Label("Inside GUI Function"); } } [26158-notingui.png|26158]
– clunk47putting it back inside OnGUI did not do anything.
– thornekeyand btw, originally, I was calling the ServerCreate function from within the OnGUI function. Not Update and public class Example : MonoBehaviour { void NotInGUI() { GUILayout.Label("Outside of GUI Function"); } void OnGUI() { NotInGUI(); } } will work.
– thornekey