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 /
  • Help Room /
avatar image
0
Question by amanuilBoku · Sep 05, 2021 at 05:24 AM · unityeditor

Give points to player and he/she hits specific target, deduct points otherwise

C# script for game manager that regulates the player to hit a specific target and if the player misses then there is a deduction from the score else if player hits a different game object then the deduction made depends on the game object that is hit

 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using ThreeDPool.EventHandlers;
 using ThreeDPool.Controllers;
 using ThreeDPool.UIControllers;
 
 namespace ThreeDPool.Managers
 {
 
     /// This class is a rule manager for this pool game
     /// decides on the players playing
     /// calculates score and decides the fate of the ball and the players after each turn
     public class GameManager : Singleton
     {    
         public enum GameType
         {    
             JustCue = 1,
             ThreeBall = 3,
             SixBall = 6,
             ThreePointRack = 15,
             SevenBall    
         }
          public enum GameState
          {
              Practise = 1,
              GetSet,
              Play,
              Pause,
              Complete
          }
     
          // update the players you would be playing this round
          [SerializeField]
          private string[] _playerNames;
     
          [SerializeField]
          private GameType _gameType;
     
          [SerializeField]
          private Transform _rackTransform;
     
          [SerializeField]
          private CueBallController _cueBall;
     
          [SerializeField]
          private GameUIScreen _gameUIScreen;
     
          // maintaining a queue here so that we dont have to worry about maintain a separate field for the player turn
          private Queue<Player> _players = new Queue<Player>();
     
          private List<CueBallController> _ballsPocketed;
          private List<CueBallController> _ballsHitOut;
          private GameState _currGameState;
          private GameState _prevGameState;
          private bool _ballsInstantiated;
     
          public int NumOfBallsStriked;
     
          public GameState CurrGameState { get { return _currGameState; } }
          public GameState PrevGameState { get { return _prevGameState;  } }
     
          public Queue<Player> Players { get { return _players;  } }
     
          public string[] Winners;
     
          public int NumOfTimesPlayed { private set; get; }
     
          protected override void Start()
          {
              base.Start();
     
              ChangeGameState(GameState.Practise);
              NumOfBallsStriked = 0;
     
              if (_playerNames != null)
              {
                  foreach (var playerName in _playerNames)
                  {
                      var player = new Player(playerName);
     
                      _players.Enqueue(player);
                  }
              }
     
              // declare the ballspotted and ballshit out array
              // consider all the balls are either potted or hitout,
              // lets fix the array size based on game type + cueball
              int arraySize = (int)_gameType + 1;
              _ballsPocketed = new List<CueBallController>(arraySize);
              _ballsHitOut = new List<CueBallController>(arraySize);
     
              // create player uis
              _gameUIScreen.CreatePlayerUI();
     
              // the first player in the queue will be playing first
     
          }
      }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

170 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 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

Unity PERSISTENT error: Assertion failed on expression: 'VCCache::instance != NULL' unity 0 Answers

Unity Failed in Native API RTVFromRenderBuffer when Get a RenderTexture Handle 0 Answers

Mac os unity iOS build Pink Screen Error 7 Answers

Where I can find a tutorial about IK? 0 Answers

Unity doesn't load textures as it should be 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