Author Topic: HUD Text Timer / point scale for cooking mini game  (Read 4101 times)

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
HUD Text Timer / point scale for cooking mini game
« on: June 07, 2014, 05:50:11 AM »
Hi Guys,

I am trying to create a custom script for playmaker that will have points increase over time and display it via the HUD Text plugin.

So I would have 3 states in playmaker.

#1 would go +1 +2 +3 +4
and you would exit out of this state via a wait action

#2 would have the +5 pause for a few seconds to allow people to get the optimum score

#3 would start taking away points +4 +3 +2 +1

Hope this makes sense what I am trying to do. Basically there is a cooking mini game and I am trying to show the points above the food. You get less time if you take it out too soon or too late.

  1. using UnityEngine;
  2.  
  3. namespace HutongGames.PlayMaker.Actions
  4. {
  5.         [ActionCategory(ActionCategory.ScriptControl)]
  6.         [Tooltip("Call Add of HUDText.")]
  7.         public class HUDTextNumbers : FsmStateAction
  8.         {
  9.                 [RequiredField]
  10.                 [CheckForComponent(typeof(HUDText))]
  11.                 public FsmOwnerDefault gameObject;
  12.                
  13.                 public FsmFloat value;
  14.                 public FsmFloat addValue;
  15.                 public FsmFloat results;
  16.                 public FsmColor col;
  17.                 public FsmFloat timeBeforeNextText;
  18.                 public FsmFloat timeBeforeFade;
  19.  
  20.                 private float timer;
  21.                
  22.                 public override void Reset()
  23.                 {                      
  24.                 }
  25.                                
  26.                 public override void OnUpdate()
  27.                 {
  28.                         // check that we have MyScript referenced
  29.                        
  30.                         GameObject      go  = Fsm.GetOwnerDefaultTarget(gameObject);
  31.                        
  32.                         if (go == null)
  33.                         {
  34.                                 return;
  35.                         }
  36.                        
  37.                         HUDText hudtext = go.GetComponent<HUDText>();
  38.                        
  39.                         if (hudtext == null)
  40.                         {
  41.                                 return;
  42.                         }
  43.                        
  44.                         timer += Time.deltaTime;
  45.                        
  46.                         if (timer >= timeBeforeNextText.Value)
  47.                         {
  48.                                 timer = 0f;
  49.  
  50.                                 results = value.Value + addValue.Value;
  51.                                 hudtext.Add(value.Value + addValue.Value,col.Value,timeBeforeFade.Value);
  52.                         }
  53.                 }
  54.                
  55.         }
  56. }

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: HUD Text Timer / point scale for cooking mini game
« Reply #1 on: June 22, 2014, 10:30:03 PM »
Hi guys,

Thought I would give this a bump.

What I am trying to do is create a script that I can give it a counter - say 1-10. And have a variable that adjusts that time. So the numbers will get displayed if its 5 or 10 seconds. The only thing that changes is there speed.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text Timer / point scale for cooking mini game
« Reply #2 on: June 22, 2014, 10:41:49 PM »
I really can't suggest much regarding PlayMaker as I don't use it.

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: HUD Text Timer / point scale for cooking mini game
« Reply #3 on: June 23, 2014, 12:06:49 AM »
Thanks for the reply.

It doesn't have to be in playmaker. If I can figure it out in c# i can later convert it to a playmaker action.

I just seem to have issues of getting the text to update/increment over a certain time. I also want to stop the increment at the press of a button or have it decrease from a number.

So it would go 1-4 over 4 seconds; pause at 5 for 2 seconds; then go 4-1 over 4 seconds. This is an example of what I am trying to  do.

As I said, if I can get it working in c# with delta time I would be happy.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text Timer / point scale for cooking mini game
« Reply #4 on: June 24, 2014, 08:10:27 AM »
  1. IEnumerator CustomUpdate()
  2. {
  3.     for (int i = 1; i < 6; ++i)
  4.     {
  5.         hudText.Add(i.ToString(), Color.white, 0f);
  6.         yield return new WaitForSeconds(1f);
  7.     }
  8.  
  9.     yield return new WaitForSeconds(1f);
  10.  
  11.     for (int i = 4; i > 0; --i)
  12.     {
  13.         hudText.Add(i.ToString(), Color.white, 0f);
  14.         yield return new WaitForSeconds(1f);
  15.     }
  16. }

joduffy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: HUD Text Timer / point scale for cooking mini game
« Reply #5 on: June 29, 2014, 08:06:10 PM »
Thanks dude,

By following your logic I was able to get it working and also get it working in playmaker :D

Thanks for you help.