user interface - unity object reset button and slider -
i want create on keyboard r button press reset object position: x112 y8 z153. object name sphere can rename it.
and want gui slider can alter forceadder 50f in game 0 500.
i beginner. finished begginer tutorials. code need get? tried create reset button self dosent me says in debug pressed dosent reset it. soo removed code.
my code right now:
using unityengine; using system.collections; public class shootmeball : monobehaviour { public float forceadder = 500f; void onmousedown() { rigidbody.addforce (transform.forward * forceadder); rigidbody.usegravity = true; } void awake() { debug.log ("i awake."); screen.lockcursor = true; gameobject.renderer.material.color = color.yellow; } }
here's solution(you need drag object you're moving scripts gameobject variable in inspector, , slider slider slot):
using unityengine; using unityengine.ui; using system; public class illustration : monobehavior { public gameobject go; public slider slider; private float force; void update() { if(input.getkeydown(keycode.r)) { go.transform.position = new vector3(112f, 8f, 153f); } forcefulness = (float)slider.value; } }
don't forget set min/max values of slider, , value "use whole numbers" true if matters.
user-interface button unity3d reset
No comments:
Post a Comment