I can't change an int from an other class
Hello, I can't change my value from an other class, and if i put this value in public, when i relaunch the game it stays at the last value it was before stopping the game. I'm trying to code a easy space invader (i'm beginner) , what I want to do is when i hit 4 times the gray vessel I want to have a super gray missile, but I didn't succed. I did try to do a sigletone ? class because in "nomal" class it didn't work, but nothing changes.
Here is my gray vessel class :
using UnityEngine;
public class EnnemyGray : MonoBehaviour { public GameObject gray; public EnnemyYellow ennemyYellow; public EnnemyGreen ennemyGreen; public Scores scores; void Start() {
 }
 
 void Update()
 {
     
 }
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("Bullet") || collision.CompareTag("SuperBullet"))
     {
         scores.AddGrayCount();
         Destroy(gray);
     }
 }
}
Here is my static class scores :
using UnityEngine;
public class Scores : MonoBehaviour { public static Scores scores; private int grayCount; public Paddle paddle;
 private void Awake()
 {
     scores = this;
 }
 void Start()
 {
     
 }
 void Update()
 {
     SetGrayPower();
 }
 public void AddGrayCount()
 {
     grayCount++;
 }
 private void SetGrayPower()
 {
     if(grayCount == 4 && Input.GetKeyDown(KeyCode.V))
     {
         paddle.GrayPower();
         grayCount = 0;
     }
 }
}
Here is my paddle class :
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Paddle : MonoBehaviour {
 float speed;
 float width;
 string input;
 public GameObject bullet;
 public GameObject bulletYellow;
 public GameObject bulletGreen;
 public GameObject bulletGray;
 public GameManager gameManger;
 private Vector3 pos;
 private bool canShot = true;
 void Start()
 {
     width = transform.localScale.x;
     speed = 10f;
     input = "Paddle";
 }
 void Update()
 {
     pos = new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z);
     if (Input.GetKeyDown(KeyCode.Space) && canShot)
     {
         Instantiate(bullet, pos, transform.rotation);
         canShot = false;
         StartCoroutine(CanShot());
     }
     //definition du mouvement du paddle en fonction des inputs
     float move = Input.GetAxis(input) * Time.deltaTime * speed;
     if (transform.position.x < GameManager.bottomLeft.x + width / 2 && move < 0)
     {
         move = 0;
     }
     if (transform.position.x > GameManager.topRight.x - width / 2 && move > 0)
     {
         move = 0;
     }
     transform.Translate(move * Vector2.right);
 }
 private IEnumerator CanShot()
 {
     yield return new WaitForSeconds(0.5f);
     canShot = true;
 }
 public void GrayPower()
 {
     if (canShot)
     {
         Instantiate(bulletGray, pos, transform.rotation);
         StartCoroutine(CanShot());
     }
 }
}
Here is my bulletGray class :
using UnityEngine;
public class BulletGray : MonoBehaviour { float speed = 1f; float radius; public GameObject bulletGray; public GameObject paddle; private bool isMoving = false;
 private void Start()
 {
     radius = transform.localScale.y / 2;
     BulletGrayMove();
 }
 void Update()
 {
     if (bulletGray.transform.position.y - radius > GameManager.topRight.y)
     {
         Destroy(bulletGray);
         LeanTween.cancel(bulletGray);
         isMoving = false;
     }
 }
 private void BulletGrayMove()
 {
     if (!isMoving)
     {
         LeanTween.moveY(bulletGray, GameManager.topRight.y + radius + 0.5f, speed);
         isMoving = true;
     }
 }
}
Your answer
 
 
             Follow this Question
Related Questions
Question about protected and abstract classes. 1 Answer
HowTo pass variable to OnGUI 0 Answers
If statement noop :) 1 Answer
Why does this part of code run twice? 1 Answer
Use a class like a function 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                