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 /
This question was closed May 18, 2019 at 12:30 PM by Bunny83 for the following reason:

Problem is not reproducible, outdated

avatar image
1
Question by Marcus_is_beast · Feb 28, 2019 at 08:25 AM · unity 5int

Trying to add 1 to a int.

Hello, I am wondering is someone could help me. I am trying to get the int value when it is less then 6 to add one. In my debug it just stays as 1.

I have included part of my code where i use the int

 public int scoreValue = 0;
 
 
 if (CurrentTile != null && CurrentTile.Player1Score)
             {
                 Debug.Log("End Title");
                 if (scoreValue <= 6)
                 {
                     
                     scoreValue += 1;
                     Debug.Log(scoreValue);
                 }
                 else
                 {
                     Debug.Log("You Win");
                 }
             }

edit( moved from answer)

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class PlayerStone : MonoBehaviour
  {
      // Use this for initialization
      void Start()
      {
          theStateManager = GameObject.FindObjectOfType<StateManager>();
          EnableObj = GameObject.FindObjectOfType<EnableMenu>();
          targetPosition = this.transform.position;
          TextControl TextControl = GameObject.FindObjectOfType<TextControl>();
          //TextControl.returnStone = returnStone;
          
      }
  
      public Tile StartingTile;
      public Tile CurrentTile { get; protected set; }
  
      public int PlayerId;
      public StoneStorage MyStoneStorage;
  
      bool scoreMe = false;
      public int ScoreId = 0;
      public int scoreValue = 0;
  
      StateManager theStateManager;
      EnableMenu EnableObj;
  
      
      Tile[] moveQueue;
      int moveQueueIndex;
  
      bool isAnimating = false;
  
      Vector3 targetPosition;
      Vector3 velocity;
      float smoothTime = 0.25f;
      float smoothTimeVertical = 0.1f;
      float smoothDistance = 0.01f;
      float smoothHeight = 0.5f;
  
      PlayerStone stoneToBop;
  
      
      // Update is called once per frame
      void Update()
      {
          
  
          if (isAnimating == false)
          {
              // Nothing for us to do.
              return;
          }
          
          if (Vector3.Distance(
                 new Vector3(this.transform.position.x, targetPosition.y, this.transform.position.z),
                 targetPosition) < smoothDistance)
          {
              // We've reached the target position -- do we still have moves in the queue?
  
              if( 
                  (moveQueue == null || moveQueueIndex == (moveQueue.Length))
                  &&
                  ((this.transform.position.y-smoothDistance) > targetPosition.y)
              )
              {
                  // We are totally out of moves (and too high up), the only thing left to do is drop down.
                  this.transform.position = Vector3.SmoothDamp(
                      this.transform.position, 
                      new Vector3(this.transform.position.x, targetPosition.y, this.transform.position.z), 
                      ref velocity, 
                      smoothTimeVertical);
  
                  // Check for bops
                  if(stoneToBop != null)
                  {
                      stoneToBop.ReturnToStorage();
                      stoneToBop = null;
                  }
              }
              else
              {
                  // Right position, right height -- let's advance the queue
                  AdvanceMoveQueue();
              }
          }
          else if (this.transform.position.y < (smoothHeight - smoothDistance))
          {
              // We want to rise up before we move sideways.
              this.transform.position = Vector3.SmoothDamp(
                  this.transform.position, 
                  new Vector3(this.transform.position.x, smoothHeight, this.transform.position.z), 
                  ref velocity, 
                  smoothTimeVertical);
          }
          else
          {
              // Normal movement (sideways)
              this.transform.position = Vector3.SmoothDamp(
                  this.transform.position, 
                  new Vector3(targetPosition.x, smoothHeight, targetPosition.z), 
                  ref velocity, 
                  smoothTime);
          }
  
      }
  
  
      void AdvanceMoveQueue()
      {
          if (moveQueue != null && moveQueueIndex < moveQueue.Length)
          {
              Tile nextTile = moveQueue[moveQueueIndex];
              if (nextTile == null)
              {
                  // We are probably being scored
                  // TODO: Move us to the scored pile
                  Debug.Log("SCORING TILE!");
                  SetNewTargetPosition(this.transform.position + Vector3.right * 10f);
              }
              else
              {
                  SetNewTargetPosition(nextTile.transform.position);
                  moveQueueIndex++;
              }
          }
          else
          {
              // The movement queue is empty, so we are done animating!
              //Debug.Log("Done animating!");
              this.isAnimating = false;
              theStateManager.AnimationsPlaying--;
  
              // Are we on a roll again space?
              if(CurrentTile != null && CurrentTile.IsRollAgain)
              {
                  theStateManager.RollAgain();
              }
              if (CurrentTile != null && CurrentTile.IsQuestion)
              {
                  Debug.Log("question PS");
                  EnableObj.Question();
                  Time.timeScale = 0f;
              }
              if (CurrentTile != null && CurrentTile.Player1Score)
              {
                  Debug.Log("End Title");
                  if (scoreValue <= 6)
                  {  
                      scoreValue ++;
                      Debug.Log(scoreValue);
                  }
                  else
                  {
                      Debug.Log("You Win");
                  }
              }
          }
          if (TextControl.returnStone == "y")
          {
                 // ReturnToStorage();
              Debug.Log("TextControl.returnStone: " + TextControl.returnStone);
              TextControl.returnStone = "n";
          }
      }
  
  
      void SetNewTargetPosition(Vector3 pos)
      {
          targetPosition = pos;
          velocity = Vector3.zero;
          isAnimating = true;
      }
  
      void OnMouseUp()
      {
          // TODO:  Is the mouse over a UI element? In which case, ignore this click.
          MoveMe();
      }
  
      public void MoveMe()
      {
          // Is this the correct player?
          if (theStateManager.CurrentPlayerId != PlayerId)
          {
              return;
          }
  
          // Have we rolled the dice?
          if (theStateManager.IsDoneRolling == false)
          {
              // We can't move yet.
              return;
          }
          if (theStateManager.IsDoneClicking == true)
          {
              // We've already done a move!
              return;
          }
  
          int spacesToMove = theStateManager.DiceTotal;
  
          if (spacesToMove == 0)
          {
              return;
          }
  
          // Where should we end up?
          moveQueue = GetTilesAhead(spacesToMove);
          Tile finalTile = moveQueue[ moveQueue.Length-1 ];
  
          // TODO: Check to see if the destination is legal!
  
          if(finalTile == null)
          {
              // Hey, we're scoring this stone!
              scoreMe = true;
                  
          }
          else
          {
              if(CanLegallyMoveTo(finalTile) == false)
              {
                  // Not allowed!
                  finalTile = CurrentTile;
                  moveQueue = null;
                  return;
              }
  
              // If there is an enemy tile in our legal space, the we kick it out.
              if(finalTile.PlayerStone != null)
              {
                  //finalTile.PlayerStone.ReturnToStorage();
                  stoneToBop = finalTile.PlayerStone;
                  stoneToBop.CurrentTile.PlayerStone = null;
                  stoneToBop.CurrentTile = null;
                  
              }
          }
          
  
          this.transform.SetParent(null); // Become Batman
  
          // Remove ourselves from our old tile
          if(CurrentTile != null)
          {
              CurrentTile.PlayerStone = null;
          }
  
          // Even before the animation is done, set our current tile to the new tile
          CurrentTile = finalTile;
          if( finalTile.IsScoringSpace == false )   // "Scoring" tiles are always "empty"
          {
              finalTile.PlayerStone = this;
          }
  
          moveQueueIndex = 0;
  
          theStateManager.IsDoneClicking = true;
          this.isAnimating = true;
          theStateManager.AnimationsPlaying++;
      }
  
      // Return the list of tiles __ moves ahead of us
      public Tile[] GetTilesAhead( int spacesToMove )
      {
          if (spacesToMove == 0)
          {
              return null;
          }
  
          // Where should we end up?
  
          Tile[] listOfTiles = new Tile[spacesToMove];
          Tile finalTile = CurrentTile;
  
          for (int i = 0; i < spacesToMove; i++)
          {
              if (finalTile == null)
              {
                  finalTile = StartingTile;
              }
              else
              {
                  if (finalTile.NextTiles == null || finalTile.NextTiles.Length == 0)
                  {
                      // We are overshooting the victory -- so just return some nulls in the array
                      // Just break and we'll return the array, which is going to have nulls
                      // at the end.
                      break;
                  }
                  else if (finalTile.NextTiles.Length > 1)
                  {
                      // Branch based on player id
                      finalTile = finalTile.NextTiles[ PlayerId ];
                  }
                  else
                  {
                      finalTile = finalTile.NextTiles[0];
                  }
              }
  
              listOfTiles[i] = finalTile;
          }
  
          return listOfTiles;
      }
  
      public Tile GetTileAhead(  )
      {
          return GetTileAhead( theStateManager.DiceTotal );
      }
  
  
      // Return the final tile we'd land on if we moved __ spaces
      public Tile GetTileAhead( int spacesToMove )
      {
          //Debug.Log(spacesToMove);
          Tile[] tiles = GetTilesAhead( spacesToMove );
  
          if(tiles == null)
          {
              // We aren't moving at all, so just return our current tile?
              return CurrentTile;
          }
  
          return tiles[ tiles.Length-1 ];
      }
  
      public bool CanLegallyMoveAhead( int spacesToMove )
      {
          if( CurrentTile != null && CurrentTile.IsScoringSpace )
          {
              // This stone is already on a scoring tile, so we can't move.
              return false;
          }
  
          Tile theTile = GetTileAhead( spacesToMove );
  
          return CanLegallyMoveTo( theTile );
      }
  
      bool CanLegallyMoveTo( Tile destinationTile )
      {
          //Debug.Log("CanLegallyMoveTo: " + destinationTile);
  
          if(destinationTile == null)
          {
              // NOTE!  A null tile means we are overshooting the victory roll
              // and this is NOT legal (apparently) in the Royal Game of Ur
              return false;
  
              // We're trying to move off the board and score, which is legal
              //Debug.Log("We're trying to move off the board and score, which is legal");
              //return true;
          }
  
          // Is the tile empty?
          if(destinationTile.PlayerStone == null)
          {
              return true;
          }
  
          // Is it one of our stones?
          if(destinationTile.PlayerStone.PlayerId == this.PlayerId)
          {
              // We can't land on our own stone.
              return false;
          }
  
          // If it's an enemy stone, is it in a safe square?
          if( destinationTile.IsRollAgain == true )
          {
              // Can't bop someone on a safe tile!
              return false;
          }
  
          // If we've gotten here, it means we can legally land on the enemy stone and
          // kick it off the board.
          return true;
      }
  
      public void ReturnToStorage()
      {
          Debug.Log("ReturnToStorage");
          //currentTile.PlayerStone = null;
          //currentTile = null;
  
          this.isAnimating=true;
          theStateManager.AnimationsPlaying++;
  
          moveQueue = null;
  
          // Save our current position
          Vector3 savePosition = this.transform.position;
  
          MyStoneStorage.AddStoneToStorage( this.gameObject );
  
          // Set our new position to the animation target
          SetNewTargetPosition(this.transform.position);
  
          // Restore our saved position
          this.transform.position = savePosition;
      }
  
  }

Comment
Comments Locked · Show 5
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 Captain_Pineapple · Feb 28, 2019 at 09:20 AM 0
Share

Can you post your whole script?

avatar image Bonfire-Boy · Feb 28, 2019 at 01:54 PM 0
Share

If you mean the debug output from line 11 is "1" then that's what one would expect from the snippet you've shown us (the variable is initialised to 0, then you add 1...)

If there actually is an issue here then like Captain_Pineapple says you need to show more than this code snippet. What you've posted wouldn't even compile.

avatar image Marcus_is_beast Bonfire-Boy · Mar 01, 2019 at 05:28 AM 0
Share

the issue is that the variable is the debug just says 1 and doesn't change even when i change the int value.

avatar image Cornelis-de-Jager · Mar 01, 2019 at 05:42 AM -1
Share

Your code looks perfectly fine. I think this might be a Unity / System bug. Try deleting the script and creating a new one. $$anonymous$$aybe restart your computer as well.

avatar image Marcus_is_beast Cornelis-de-Jager · Mar 01, 2019 at 06:04 AM 0
Share

I restarted my computer, same problem, so then i deleted the script and created a new one and same problem is occurring.

2 Replies

  • Sort: 
avatar image
-5
Best Answer

Answer by Marcus_is_beast · Mar 01, 2019 at 07:23 AM

I Manged to Fixed the issue my self all i did was change.

 public int scoreValue = 0;

to

 public string int scoreValue = 0;

It all works now

Comment
Comments Locked · Show 3 · 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 WarmedxMints · Mar 01, 2019 at 07:45 AM 0
Share

That wouldn't compile. Something else is going on.

avatar image Marcus_is_beast WarmedxMints · Mar 01, 2019 at 08:04 AM 0
Share

well everything works now it compiles and it goes up by one every time.

avatar image Bunny83 Marcus_is_beast · Mar 04, 2019 at 12:16 PM 1
Share

No, this for sure does not compile. Did you mean:

  public static int scoreValue = 0;

Your current answer is misleading and wrong.

avatar image
1

Answer by mourad-bakhali · Feb 28, 2019 at 05:56 PM

Do you change "scoreValue" outside of the 'if' block ? Normally your code should print "1, 2, 3, 4, 5, 6, 7" !

Comment
Comments Locked · 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 Marcus_is_beast · Mar 01, 2019 at 05:27 AM 0
Share

@mourad-bakhali No, they is nothing outside the if statement, my code should print 1, 2, 3, 4, but ins$$anonymous$$d it just stays as one 1, 1, 1.

Follow this Question

Answers Answers and Comments

197 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Animation depending on the Int value 0 Answers

Get the number of false bools in GameObject[] (array) 3 Answers

Why my keypad shows 4x the number in input? 2 Answers

Can't set an int from seperate script 1 Answer

How to transfer time script to 24 hours and not decimals 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