Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ITSLEO · Apr 13, 2019 at 07:19 AM · timerscorescore systemtimer-script

How to give points after certain number of seconds?,How to give points after a certain number of seconds?

Hi everyone! So basically i made the whole game and its almost ready, but one of the few scripts that i need is a score script, but unlike other little project i made, this one is making me struggling for almost a week now..what i want is this: Make a script where once the player starts moving, it starts a timer, and every three seconds, if the player has not died yet, it recieves 10 points.

Now, i have tried with coroutines, while loops..but nothing seems to work? Maybe i'm writing something wrong...i really hope one of you can help me out with this one!,Hi everyone! So i basically made the whole game (i'm a beginner but with a little bit of experience, still learning tho) and the only script that i need to finish the beta is a score script... its almost a week i'm struggling make a script like this:

Make a script where when the player starts moving, it starts a timer. And every three seconds, if the player has not died yet, it gives 10 points.

Now, i tried with coroutines, while loops...but nothing seems to work! Hope some of you can help me out with this one :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by highpockets · Apr 13, 2019 at 07:35 AM

You were correct by using coroutines, but there may have been an error in your logic. Here is an example for your situation:

 //I don’t know how you get your player movement, so I’ll put a bool that’s false until his initial start position is different from his position
 
 bool playerMoving = false;
 bool countPoints = false;
 Vector3 startPos;
 GameObject player;
 
 void Start(){
 player = GameObject.Find(“PlayerName”);
 startPos = player.transform.position;
 }
 
 void Update(){

 if( player.transform.position != startPos && !countPoints){
 playerMoving = true;
 }
 
 if(playerMoving){
 StartCoroutine(PointCounter());
 countPoints = true;
     playerMoving = false; //set to false to ensure you don’t start multiple coroutines
 }
 }
 
 int pointCounter;
 
 IEnumerator PointCounter(){
 
 while(countPoints){
 yields return new WaitForSeconds(3);
 pointCounter = pointCounter + 10; //add to score
 }
 }

Hope that helps

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ITSLEO · Apr 16, 2019 at 08:55 PM 0
Share

hi...first of all thank you for your kind help! :) ...so..what worked was the initial timer. What didn't work was the coroutine beacause it gives me an error with every line that has "countPoints" in..dunno why tho...basically my problem is that the player dies when a sort of arm rotates more than a certain angle, at that point i thought that something like this could work: (note its not the actual code)

bool IsAlive; bool IsDead;

in the start function i putted: GetComponent; to get the rotation values in the update:

if(transform.rotation<80 or <-80) { bool IsAlive = true; }

if(IsAlive) {

//here i would put the IEnumerator for the point count and the timer. But it doesn't work for shit.

}

if(transform.rotation>80° or >-80°) { bool isDead = true; }

if(isDead) { //game over shit and all that, it stops to count points }

also, i know i can't get the rotation axis values (its a 2d game) like this...and i searched a lot, and just found a lot of complicated and poor explains about quaterions...i don't need that much complicated shit, i just want to know what angle my player's arm is... :(

avatar image highpockets ITSLEO · Apr 16, 2019 at 09:30 PM 0
Share

I changed my code. I accidentally declared cointPoints twice.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

107 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I do I time-base score script 0 Answers

Pause Time.time? 1 Answer

How do I code time based score unity3d 3 Answers

3 star time base system 0 Answers

How do you stop a score counter when you die 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges