• Advertisement

Recommended Posts

I'm new to coding and I'm trying to learn as I go along. I had an idea for a kind of speed input game, where a 3 arrow code randomly generates and then you need to complete it left to right.

I have figured out how to randomly generate the code, including the visual prompts but the issue I'm having now is figuring out how to enforce the left to right input I want. 

I'm guessing a massive part of it is all three image objects I use, use the same code. So then do I need to make separate codes for each one and then?..... and even still I'm having trouble figuring out how to actually do the enforcement of input order. 

Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement

How do you create the random code? Do you have any way of knowing what code it is? Or are they just images? In some way you will have to know what the code is, and in what order they are. From there on there are several simple ways of making sure the user clicks in order. I guess the simplest would be to keep the code in a collection of some sort, array, list. And then loop through that collection while the user inputs, is the input the correct one? Continue one index up and try the next one. This make is easy to add more to the code, as well as resetting if the user entered the wrong code, just reset the index.

If i understood it correctly.

Share this post


Link to post
Share on other sites

You're going to need to build a controller that accepts ALL input, and compare it to the input you're expecting.

Create a class with two variables
Button
Completed

And then fill them into an array of x, make sure that youre code doesn't process the next button in line unless the value of completed on the previous is true.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By debrice
      Strange Engine is a 2D KIT for Unity Developers, which can be used to create a top down game. Or use its modules in other projects. This KIT is easy to modify as many variables can be tweaked, the scripts are neat and well documented, and Editor Extensions will help you to create new maps and weapons in one minute. You can use existing graphics or replace it with your own.
      Key Features
      > Fully Mobile Support.
      > Fully PC Support.
      > Randomly Generated map.
      > Pickups (Ammo).
      > Object Pooling.
      > Explodable walls.
      > Saves your highscore.
      > 14 different weapons.(Lasers, Lightning Bolts, Machine Guns, FlameThrowers, GrenadeLaunchers )
      > Extended Enemy AI.(fly mode, search , atack, pursuit mode, passive mode.)
      > Different enemy types (Duck, Monster, Raven).
      > Editor Extensions.
      > Mobile and PC player and shooting controls.
      > Well Optimized.
      Store Link.
      Youtube Link.
      Soon new 2D weapons pack.
      Get all news in my Twitter.

      Thanks for your time,
      Denis Arhipov
      CHE games.

      If you have any questions, please contact me here, or debrice@bk.ru.


      View full story
    • By flodihn
      Hello guys, I just want to share some of my findings after more than 10 years of software development. 
      During my last project, I made the decision for our dev team to go against what is quite commonly the default programming behaviour in Unity and most likely many other game engines. What we put all persistent data (as serialisable JSON) in a separate layer and use static functions to operate on those. This is more similar how C would operate, or most functional programming languages.
      It worked very well and caused no problem for us, so now I decided to take it one step further and make a sub system in Unity that facilitates that coding style in a more generalised way. I call this system AOEngine.
      This sub system looks like this:
      Model -> Stores data as json serialisable objects, dictionaries or both.
      View -> Listens to model, reacts when data is create, changed or destroyed and tries to render the object. The view is a monobehaviour and can be seen in the Unity Editor unlike the model and the controller.
      Controller -> Runs a state machine which executes game specific code that creates, updates or destroys data.
      State Machine -> Switches/keep/updates the global state of the game.

      The model, view and controllers are standard OOP classes communicating with interfaces using a observer pattern. So far everything is pretty standard.
      But when you realise that after separating the logic and data, what you have left are logic classes that always the same, just executing on different types of data. This means there is no need to instantiate pure logic and using static classes is actually a pretty neat idea.
      The reason static classes are getting quite a bad reputation is that in most cases they are used to share some global state, and easily become a tight dependency to many other areas in the code. But when the static class is just pure logic, we do not have this problem.
      The AO engine provides one point of entry, a GameInit prefab which is used to create the model, view and controller, the user have to provide an initial state for the state machine to run. When you import the AO Engine as a Unity package, you just need to drop one prefab into your scene, and that is the only prefab you need to start. 
      Here is the code for the GameInit:
      { public class GameInit : MonoBehaviour { public GameObject viewPrefab; public string InitialState; void Start() { IModel model = new AOEngine.Model.Model(); IView view = CreateUnityViewFromPrefab(); IController controller = new AOEngine.Controller.Controller(); view.Setup(model); controller.Setup(model, view); StateMachine.Setup(model); GameState initialGameState = TryCreateInitialGameState(); StateMachine.SwitchState(initialGameState); } The InitialState have to be defined in the Unity editor, you give it the full name to the initial game state for your game, for example MyGame.MenuGameState, then you have to make sure this class exists (goes without saying) and it must inherit AOEngine.StateMachine.GameState.
      This is how the a game state would look like:
      namespace MyGame { public class MenuGameState : GameState { public override void OnEnter() { GameObjectData uiCamera = new GameObjectData { {"uid", "camera"}, {"prefab", "Cameras/UICamera"} }; model.CreateData<GameObjectData>(uiCamera); UIData mainMenuData = new UIData { {"uid", GameUids.MAIN_MENU_DATA}, {"prefab", "UI/Prefabs/MainMenuCanvas"} }; model.CreateData<UIData>(mainMenuData); controller.BindLogic(typeof(MainMenuLogic), mainMenuData); And here is where things get interesting, first I create the some data, all data should have a unique uid to identify it, if no uid is given the model will generate an uid automatically. Optionally, a piece of data can be bound to one or more logic classes, which are static, using the controller.BindLogic providing the logic class and the data uid to bind it to. This is basically a component system, but not using monobehaviours or standard OOP.
      The static logic class would look something like this:
      namespace MyGame { public static class MainMenuLogic { private static IModel model; [OnLogicSetup] public static void Setup(IModel _model) { model = _model; } [OnLogicCreate] public static void OnCreate(string dataUid) { UIData data = model.GetData<UIData>(dataUid); model.UpdateProperty(data, new Dictionary<string, object> { { "ui_callbacks", new Dictionary<string, object> { {"OnButtonClicked", "MyGame.MainMenuLogic#OnButtonClicked"} }} }); } [OnLogicUpdate] public static void OnUpdate(string dataUid) { UnityEngine.Debug.Log("MainMenuLogic.OnUpdate"); } [OnLogicDestroy] public static void OnDestroy(string dataUid) { model.DestroyData(GameUids.MAIN_MENU_DATA); } public static void OnButtonClicked(string buttonName) { if(buttonName == "QuitButton") UnityEngine.Application.Quit(); if(buttonName == "StoryButton") { StateMachine.SwitchState(new StoryGameState()); } } } } So not being a fan of monobehaviours, I use them to a minimum, only for position translations, particle systems, collision detection and audio playing, and then these monobehaviours would be bare components without any logic or state.
      I need to figure how communication between my static components, I will probably use a game event system for this. 
      So far I am quite happy with system where all my logic are running in static classes. I wonder if there are any other people out there that reached the same conclusions, what are your opinions of this approach?
    • By Redlime
      I am a game development student working on a 2.5D beat 'em up brawler game in Unity as my final year project and I've been working on the ai for the enemies in the game. However, I've been unable to get the enemies to working properly as the enemies would be constantly stuttering and jerking while trying to follow the player. I've created a foreach statement and added some conditions that call for the robots to spread out and stay away from the player if it is not in an engaging enum state. This has been an issue plaguing the ai for a while now, analysing the animator, it seems like the robot's movement is instantaneously stopping and going which might be the reason causing this stuttering. But I'm not sure how to prevent the robot's movement from stopping and going. If anyone knows the reason why this is happening to the robots it would be much appreciated as my project is due soon and I'm still unable to fix such a game breaking bug! I've included a few videos below showing what is happening to my robots and also the stuttering shown inside the animator. I've also included the full script for my robots.
       
      Robots Stuttering
      Robots Stuttering Animator
      Robot.cs
    • By harugawa
      Alright, I'm not even sure if I write my first post in the right sub category. 
      Basically I'm creating some browser game based on .net and you got there an inventory with a bunch of potions. I'm just not really sure how to handle different potions and its usage on the backend to not make it into a spagetti. So, whenever user clicks on the potion, it sends an id of the potion to the api endpoint, I'm checking there the type and just getting the info about potion. I got an enum which describes the type, like mana, hp, energy, exp or you name it. 
      So what now. Do I make like a huge switch statment and just pass it to a different methods or something and do there what has to be done with the potion? Sorry for not showcasing any code, but I do not have any for this, just trying to brainstorm how to implement some potion usage mechanics. Am I going the right direction or I just missed the path and heading to the dead end?
       
    • By Klebs
      Hey so, i need help in how to sync animations using Forge Networking i tried sometings but nothing
  • Advertisement