- Home /
GUI Question please help.
i really need this so im making a multiplayer game and ive got texture for the HUD and i want it to move when i move my mouse and stuff like battlefield. like his: https://www.youtube.com/watch?v=csA9Ie5nXoQ
in that video the HUD moves when he jumps and runs or moves the mouse that's what i want please help just tell me whats it called and ill get tutorials my self .( i know this might be stupid question.)
Answer by DBar · Aug 19, 2014 at 07:27 AM
Hello, this is a AAA production so take that in mind first.
The HUD effect is made with a tweening operation, maybe from code.
I did it myself more humble with NGui plugin, it has a Tween Component that i applied to my HUD that i trigger on crash.
ok thanks i have ngui il try it. thanks for helping your awesome.
Answer by senc01a · Aug 19, 2014 at 07:35 AM
This should't be too complicated. First you need to define how you want to the HUD to move. For instance, you can say, if my player is jumping, I want the HUD to tilt slightly down while he is doing so. Now you can check your PlayerController and look at if the player is gounded or not, if it is not, you can tween the hud a few pixels down, and as soon as the player is grounded again, you can tilt it a few pixels up.
Assuming you are using a (proper) GUI framework, like NGUI, the simplest way would be to add a reference to the HUD gameobject to your PlayerController script. In the update function of your PlayerController you could do something like (the following code is untested, just wrote it here in the editor):
public Gameobject hud;
private bool hudIsShaking = false;
private const float shakeDuration = 0.5f;
void FixedUpdate(){
/* ...
.... */
Vector3 direction = new Vector3(0.0f, 1.0f;, 0.0f);
if (!grounded && !hudIsShaking){
hudIsShaking = true;
StartCoroutine(TweenHud(direction));
}else if (grounded && hudIsShaking){
hudIsShaking = false;
StartCoroutine(TweenHud(direction * -1f));
}
}
IEnumerator TweenHud(Vector3 direction){
float duration = 0.0f;
Vector3 hudInitialPosition = hud.transform.position;
Vector3 hudTargetPosition = hudInitialPosition + direction;
while (duration < shakeDuration){
duration += Time.deltaTime;
hud.transform.position = Vector3.Lerp(hudInitialPosition, hudTargetPosition, duration / shakeDuration);
yield return null;
}
}
thank you so much i will try it. im using unitys built in gui but now im going to use a gui texture. and also does this only work on ngui(the script)
It can work anywhere. What that script does is tween a gameobject (your hud for instance) when the player controller detects that the player is jumping.
Your answer
Follow this Question
Related Questions
Runescape style window? 1 Answer
Multi Camera HUD buttons not working. 1 Answer
gui or 3d model for hud ? 1 Answer
Best way to create mini hp-bars for enemies. 1 Answer
How to position 3D-GUI-Mesh on change of aspect ratio? 0 Answers