Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 hollym16 · Mar 05, 2015 at 11:15 AM · animationtriggercharacterscoreaugmented-reality

Scoring System

Here's what I want to do: Character 1 comes onscreen which has a score/rating. Then Character 2 comes onscreen which also has a score/rating.

If Character 1 has a higher score/rating, play animation 'Victorious' and Character 2 play animation 'Defeat'. And vice-versa.

Anyone know how I would go about employing a score/rating system? Thanks

Comment
Add comment · Show 3
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 HarshadK · Mar 05, 2015 at 11:30 AM 0
Share

What have you tried?

avatar image hollym16 · Mar 06, 2015 at 04:12 PM 0
Share

I've got this script which works in a very confined sense:

 using UnityEngine;
 using System.Collections;
 
 public class WinLose : $$anonymous$$onoBehaviour {
 
     public int Car1Speed = 196;
     public int Car2Speed = 205;
     private GameObject Win;
     private GameObject Lose;
     // Use this for initialization
     void Start () {
         Win = GameObject.Find ("Cube");
         Lose = GameObject.Find ("Cylinder");
         Win.SetActive(false);
         Lose.SetActive(false);
     }
     // Update is called once per frame
     void Update () {
     
         if(Car1Speed > Car2Speed){
             Win.SetActive (true);
             Lose.SetActive(false);
         }
             else{
                 Win.SetActive(true);
                 Lose.SetActive(false); 
             }
     }
 }
 

However, the trouble is my $$anonymous$$d boggles when I think that I have to apply this to maybe 100 models and how I would go about defining them. I obviously can't do them all like the above as that a ridiculous amount of variations.

Is there any way I could do a script along these lines:

Each model has the same script saying find this models 'speed' and find the other models 'speed' (whichever model that may be). Then if this models number is bigger than the other, do something, and if not, do something else.

I feel I'm getting a little closer, I just need a point in the right direction on this.

avatar image Mmmpies · Mar 06, 2015 at 04:23 PM 0
Share

What you need to do is type:

Unity polymorphism

In google. Top link should be the Learn tutorial. Also watch the one on Inheritance.

Again sorry for typos, on my phone.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by uanmanarmy · Mar 05, 2015 at 11:56 AM

You could simple check it.

Grab the both scores and make a check and in that check place your animation call.

Comment
Add comment · Show 7 · 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 hollym16 · Mar 05, 2015 at 01:01 PM 0
Share

This is what I'm struggling with, not grabbing and checking the scores, but assigning them in the first place. I'm thinking numerical value so the script can check 'if number is above, trigger one animation, else trigger other animation'

avatar image Mmmpies · Mar 05, 2015 at 03:26 PM 0
Share

Would it be safe to say you want a random number in range to assign to each character when they appear. If so look up Random.Range.

Say you want to assign a value between 5 and 20:

 Random.Range (5,21);

The upper value is exclusive of using int so set it to 1 above the upper number.

Sorry for typos, on my phone.

avatar image hollym16 · Mar 06, 2015 at 11:23 AM 0
Share

Hey thanks for the reply. I don't want it to assign a random number. I want each character to have a specific value. For example, if a goon enemy comes onscreen, he would have a numerical value of 1. Whereas a boss enemy would have a value of 100. Thus the boss enemy would 'win' as 100 is a bigger number than 1. Any clues?

avatar image Mmmpies · Mar 06, 2015 at 11:40 AM 0
Share

Well you can just set that in a script attached to the character or you could store it in an array and assign each character a number.

Is this just one value for each character or a lot of different values like strength, agility, defence skills etc?

And are these values likely to change over time?

PS something wrong with my account so Im not getting mail updates, so sorry if I appear to go quiet.

avatar image hollym16 · Mar 06, 2015 at 11:42 AM 0
Share

I was going to start off with just the one value but expand into multiple values. The idea that each player chooses a character then a category is chosen (i.e. speed) then whoever has the highest value wins.

Show more comments
avatar image
0

Answer by hollym16 · Mar 09, 2015 at 03:59 PM

Ok, I've got this so far, which may help some people. I've got a script on 'Car2' like so:

 using UnityEngine;
 using System.Collections;
 
 namespace Car{
 public class WinLose1: MonoBehaviour {
     public int Car2Speed = 205;
 }
 }

Then on 'Car1' I've got this script:

 using UnityEngine;
 using System.Collections;
 using Car;
 
 public class WinLose : MonoBehaviour {
     
     public int Car1Speed = 196;
     private GameObject Win;
     private GameObject Lose;
     public GameObject gameControllerObject;
     public WinLose1 gameController;
     
     void Start () {
         Win = GameObject.Find ("Cube");
         Lose = GameObject.Find ("Cylinder");
         Win.SetActive(false);
         Lose.SetActive(false);
         gameControllerObject = GameObject.Find ("/ImageTarget2");
         gameController = gameControllerObject.GetComponent<WinLose1>();
     }
     void Update () {
         int NextCar = gameController.Car2Speed;
         if(Car1Speed > NextCar){
             Win.SetActive (true);
             Lose.SetActive(false);
         }
         else{
             Win.SetActive(false);
             Lose.SetActive(true); 
         }
     }
 }

This accesses the other script and gets the int value which the determines whether to display the Cube or Cylinder (i.e. win or lose).

The next things I need to do are:

Make it only find the int value when the opponent is on screen. (OnTrackingFound?)

Make it reciprocal so they are looking for each others int values and displaying win or lose depending on each others values.

Alter the script so it's not just reading from one external script but whichever script is attached to the model that comes on screen.

This is a lot more complicated than I originally thought but I'm determined to crack it now!

Comment
Add comment · Show 1 · 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 Mmmpies · Mar 09, 2015 at 05:11 PM 0
Share

Careful formatting that code, I've corrected it this time.

Why not have a prefab car, hold the Car speed in an Array. When you want the car on the screen instantiate it and pick up the car speed from the array.

Just check the values in the array.

So create a public int array for testing:

 public int[] CarSpeed;

This is in a script attached to something in the scene. Also hold the currentCar number and the nextCar number in that script both as ints.

 public int currentCar;
 public int nextCar;
 public Vector3 CurrentCar;
 public Vector3 NewCar;
 public GameObject carPrefab;
 
 void Start()
 {
     GameObject newCar = (GameObject)Instantiate(carPrefab, CurrentCar, Quaternion.Identity);
     currentCar = 0;
     nextCar = 1;
     newCar.GetComponent<$$anonymous$$yCarScript>().CarNumber = currentCar;
     newCar.GetComponent<$$anonymous$$yCarScript>().CarSpeed = CarSpeed[currentCar];
 }

When the game starts Instantiate the first car and have the prefab hold a script with the cars public int number (CarNumber) above and it's speed from that Array (CarSpeed) above;

Now I don't know how you want to create the next car but let's say you have a button you click that calls a function in the same script when you want a new car but uses the nextCar number and also increase that number by one. Place the car in the NewCar Vector3.

Typed without testing so there may be errors.

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

22 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

Related Questions

Script does not work on version 4.6.0. 0 Answers

Character Aiming 1 Answer

How to handle multiple animation variants 1 Answer

import softimage mod tool 7.5 to unity, good or not? 0 Answers

Animations: just making sure my workflow is right. 1 Answer


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