I wanna have an action key, like a lot of games, such as hitting e will cause an animation to happen if you are with in 1 foot from an object Thanks!
you cant just say i want this ! you have to explain it better... and what do already have ? what kind of genre is your game ? (typ)
function Update () { if (Input.GetButtonDown ("Action")) animation.Play(); } What more is there to explain? genre really has nothing to do with this question, i could use the script i need for any game really. It's 3rdPS. And i've seen plenty of people say on here, what they are looking for and get multiple answers, without telling what genre their game is lol
Looks like you answered your own question mattconley. Just script it in a way that makes sense for your game.
lol. Yup you answered your own question. I think you might want to take a look at event systems, i think thats where youre going with the question.
The simplest form of it is essentially; if event ----->trigger(event) So some condition has been met, we must handle this event. You could create a singleton like object which manages these events or each object could manage it. There is many ways to get an event manager set up but its all very game specific so you would have to code it in a way that suits your game.
See this if you don't understand scripting in general: http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long) Or these if you're just stuck on Input: http://unity3d.com/support/documentation/ScriptReference/Input.html http://unity3d.com/support/documentation/Components/class-InputManager.html
What are you asking for? Tutorials on how to script in general or tutorials on how to create an "action button" for which we already explained that it's too general of a case and relatively simple to script?
I'm not finding anything on this, i want the action key enabled only when so close of range of an object
If you have even the slightest understanding of Unity, game logic, and scripting in general, this should be fairly simple to code. If you can't figure it out, you might want to consider a programming class or coding a few pong type games before attempting to create a full-blown shooter.
This is a simple way to do it, will need work if you need a door opening or something, but will work. Sorry if this is written badly, done it quick and have never had good grammar and spelling. Remember Triggers they are excatly what you want, when said criteria are met then do stuff. Action Area script - Add a collider then make it a trigger actionArea.js This script should be attached to a game object which has a collider of sorts that has the "is Trigger" ticked. Drag your player into the "theUser" varible and when your player is in the collider area the script will comminucate with the script below telling it that the criteria are met allowing actions such as animations and more. Code (csharp): var theUser : GameObject; //the player var actionStuff : actionScript; //the script contianing the input and animation stuff function OnTriggerEnter (myTrigger : Collider) { if(myTrigger.gameObject == theUser) { Debug.Log("You are in the action area"); actionStuff.canAction = true; Debug.Log(actionStuff.canAction); } } function OnTriggerExit (myTrigger : Collider) { if(myTrigger.gameObject == theUser) { Debug.Log("You left the action area"); actionStuff.canAction = false; Debug.Log(actionStuff.canAction); } } Animation Input Script actionScript.js The script above returns a boolean to this script and if this boolean equals true then when your press "Fire1" the actions you will want can be performed and wont be perfomed if the boolean equals false. Code (csharp): var canAction : boolean = false; function Update () { if(canAction) { if(Input.GetButtonDown("Fire1")) { //Play animation, do stuff } } } May need proof reading, may of made errors as I have done it quick. Tomme
not getting any errors, but i can't apply the action script, and it doesn't send the debug message when i enter the trigger