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 Bowsen · Jul 01, 2020 at 10:27 AM · functionclassvaluesingletonadding

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;
     }
 }

}

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

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

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


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