- Home /
Some questions by noobie me
Hello!
I have some problems,i beginned only few days ago.
So i attached a Flashlight to my character,and an Light ''effect/lamp''. It works perfectly,but i want to switch it on/off. I'm in trouble. I dont know where to start/create a new script,than where to place it. In script,i don't know how to point to an direct object. I want the script only for the ''FlashlightLight''. When i press F,the Light activates,turns on.When i press F again,it turns off/the light will be inactive. Anyone can help?
Here is the 2nd problem :/ When i find answer to first,this will be probably easy. I want to hold Shift,and while Shift is holded down,increase the speed of my character.
The third: Can i attach images directly to the characters camera/screen? I made an frame in GIMP for the health bar. How can i make it?
Thank you guys/girls!
Answer by ScroodgeM · Aug 05, 2012 at 12:14 PM
answer 1
LghtSwitcher.cs
using UnityEngine; using System.Collections; public class LightSwitcher : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.F)) { light.enabled = !light.enabled; } } }
save it to assets folder anywhere and then attach (drag-n-drop) to the light object in scene
answer2
just add to character's control script interaction with Input.GetKey(KeyCode.LeftShift)) to modify speed similar to previous script
answer 3
check Unity GUI mechanism
http://docs.unity3d.com/Documentation/Components/gui-Basics.html
it's very basics but enough to understand how it works.
But how can i make an GUI with texture? i want an frame,i made/draw in GI$$anonymous$$P,in the corner
Answer by Hydraxia · Aug 05, 2012 at 01:54 PM
The 3. is very useful.
But i dont understand the first. (i understand,but doesn't work) The light is automatically turned on,so i can't swith it up,or down,because 1. its turned on 2. i dont know how to turn off/down
And at answer2,i dont know how to change the speed,don't know how,or what script to use :/
1
light.enabled = !light.enabled;this line inverts current light state, so it switches it on if it off and switch off is it on.
2
this depends on what move controller you use, you should know from this controller where it stores a speed or how it can be configured.Answer by Hydraxia · Aug 05, 2012 at 04:51 PM
This light doesn't work. Or just i'm idiot.
I have Character,and there the Camera and the Flashlight (It doesn't have model yet)
I made this script,and put in the Flashlight. Right?
I start game,the flashlight is automatically turned on,but i press F,nothing happens :/
your flashlight - what exactly is this? this script is for any light in Unity, light that illu$$anonymous$$ates light and make all things aroung affect by light. this light is turned on/off by this script.
in unity hierarchy select Create - Direction light, scene should be affected by this light
drag-n-drop my script to this light
run game
press f, light should be switchen on/off.
if you 'flash light' is something another, not the one of unity light, then i understand you wrong.
Answer by reptilebeats · Aug 05, 2012 at 06:12 PM
seeing as you are new i would a advise you to look for will goldstone on youtube and follow all his tutorials step by step, they will take you a couple days to complete depending on how many times you repeat them.
this is what i followed when i first started with no previous experience in anything except from music and they helped a lot, i also saved all the scripts as a reference which have now been deleted as its all in memory now and i understand it better
Your answer
Follow this Question
Related Questions
how to have an object positioned relative to the screen(like a button) 1 Answer
UI render doesn't sync with Camera movement 2 Answers
Finding the faces of a collider box and framing them in camera 0 Answers
Camera zoom while keeping an off-center object at the same screen co-ordinates 1 Answer
How to apply screen wrapping fit for any resolution? 0 Answers