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 oshiwota · Jan 12, 2021 at 01:51 PM · public variable

public script not showing in inspector

Hi! I have a problem with this public variable which isn't showing in the inspector. I have looked at other threads and none of them helped me. If you can please help me soon.

Thanks, oshiwota

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.InputSystem;
 using TMPro;
 public class MovingScript : MonoBehaviour
 {
     public GameObject menu;
     public TMP_Text total_coinsText;
     public TMP_Text score;
     float coins = 0;
     static float total_coins = 0;
     public GameObject vig;
     public UnityEngine.UIElements.Slider health;
     private float sec = 3;
     public Sprite regularFace;
     public Sprite GrossedOutFace;
     public GameObject head;
     [HideInInspector]
     public bool isHurt;
     public GameObject point;
     public MyController controls; // It is this one
     public GameObject bullet;
     public GameObject Arm2;
     Animator anim;
     bool won = false;
     bool Grounded;
     public float size; public Vector3 offset;
     Rigidbody2D RB;
     public void quit()
     {
         Application.Quit();
     }
     public void Menu()
     {
         SceneManager.LoadScene("MenuScene");
     }
     public void win()
     {
         if (won == false)
             total_coins += coins;
             Time.timeScale = 0;
             total_coinsText.text = "Cheese: " + total_coins.ToString();
             menu.SetActive(true);
             won = true;
             return;
     }
     public void addCoin()
     {
         coins += 1;
     }
     void Hurt()
     {
         if (sec <= 0)
         {
             isHurt = false;
             sec = 3;
             head.GetComponent<SpriteRenderer>().sprite = regularFace;
 
         }
         else
         {
             health.value -= 0.0004f;
             sec -= 0.005f;
             head.GetComponent<SpriteRenderer>().sprite = GrossedOutFace;
         }
     }
     void isGrounded()
     {
         Collider2D[] things = Physics2D.OverlapCircleAll(offset+transform.position, size);
         foreach (Collider2D i in things)
         {
             if (i.gameObject.tag == "Ground" || i.gameObject.tag == "Enemy" || RB.velocity.y == 0)
             {
                 
                 Grounded = true;
             }
             else
             {
                 Grounded = false;
             }
         }
         
     }
     // Start is called before the first frame update
     void Start()
     {
         Time.timeScale = 1;
         anim = GetComponent<Animator>();
         RB = GetComponent<Rigidbody2D>();
     }
     void RotateArm()
     {
         Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - Arm2.transform.position;
         difference.Normalize();
         float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
         Arm2.transform.rotation = Quaternion.Euler(new Vector3(0, 0, rotationZ));
         if (rotationZ < -90 || rotationZ > 90)
         {
             
             
             if (transform.eulerAngles.y == 0)
             {
                 Arm2.transform.localRotation = Quaternion.Euler(180, 0, -rotationZ);
             }
             else if(transform.eulerAngles.y == 180)
             {
                 Arm2.transform.localRotation = Quaternion.Euler(180, 180, -rotationZ);
             }
         }
     }
     public void Shoot()
     {
         GameObject bul = Instantiate(bullet);
         bul.transform.rotation = Arm2.transform.rotation;
         bul.transform.position = point.transform.position;
     }
     // Update is called once per frame
     void Update()
     {
         if (health.value <= 0)
         {
             SceneManager.LoadScene(1);
         }
         if (!won)
 
             if (Input.GetKeyDown(KeyCode.C))
             {
                 anim.SetTrigger("AxeTree");
             }
             score.text = coins.ToString() + "x";
             if (Input.GetKey(KeyCode.S))
             {
                 vig.SetActive(true);
                 Time.timeScale = 0.3f;
             }else if (Input.GetKeyUp(KeyCode.S))
             {
                 vig.SetActive(false);
 
                 Time.timeScale = 1;
             }
             if (isHurt == true)
             {
                 Hurt();
             }
             controls.Player.Shoot.performed += _ => Shoot();
             Vector3 lookAtTargetPos = Camera.main.WorldToScreenPoint(Input.mousePosition);
             if (lookAtTargetPos.x <= 100210f)
             {
                 transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
             }
             if (lookAtTargetPos.x > 100210f)
             {
                 transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
             }
             RotateArm();
 
             if (Input.GetAxisRaw("Horizontal") == 0)
             {
                 anim.SetFloat("Speed", 0);
             }
             isGrounded();
             RB.velocity = new Vector2(Input.GetAxis("Horizontal") * 5, RB.velocity.y);
             if (Input.GetAxisRaw("Horizontal") == 1)
             {
                 anim.SetFloat("Speed", 1);
 
                 transform.rotation = Quaternion.Euler(new Vector3(0, 0));
             }
             if (Input.GetAxisRaw("Horizontal") == -1)
             {
                 anim.SetFloat("Speed", 1);
 
                 transform.rotation = Quaternion.Euler(new Vector3(0, 180));
             }
 
 
             if (Grounded)
             {
             
                 if (Input.GetButton("Jump"))
                 {
                     anim.SetTrigger("IsJump");
                     RB.velocity = new Vector2(RB.velocity.x, 6);
                 }
             }
         
         }
     private void OnEnable()
     {
         controls.Enable();
     }
     private void OnDisable()
     {
         controls.Disable();
     }
     void OnDrawGizmos()
     {
         Gizmos.color = Color.green;
         Gizmos.DrawSphere(offset+transform.position, size);
     }
 
 }
 
Comment
Add comment · Show 2
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 Llama_w_2Ls · Jan 12, 2021 at 02:43 PM 0
Share

Does your $$anonymous$$yController script have a $$anonymous$$onoBehaviour on it?

avatar image oshiwota Llama_w_2Ls · Jan 12, 2021 at 04:13 PM 0
Share

No it doesn't

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jackmw94 · Jan 12, 2021 at 04:44 PM

I expect the issue is that MyController is not serializable.

To fix this, add the [Serializiable] attribute at the top of the class like so:

 [Serializable]
 public class MyController


And see if that helps. If it doesn't, please post your MyController code! :)

Comment
Add comment · Show 23 · 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 oshiwota · Jan 12, 2021 at 04:45 PM 0
Share

ok i'll try that. Thanks for the feedback!

avatar image oshiwota · Jan 12, 2021 at 04:55 PM 0
Share

When i change it to a class it shows errors everywhere I use it. For some reason it won't let me put all the code of the $$anonymous$$yController Script.

avatar image jackmw94 oshiwota · Jan 12, 2021 at 05:00 PM 0
Share

What is it currently? If it's a struct then keep it one :)

  [Serializable]
  public struct $$anonymous$$yController



If that has issues, post your $$anonymous$$yController with your reply

avatar image oshiwota jackmw94 · Jan 12, 2021 at 05:05 PM 0
Share

It keeps bringing the same errors '$$anonymous$$ovingScript.$$anonymous$$yController' does not contain a definition for 'Player' '$$anonymous$$ovingScript.$$anonymous$$yController' does not contain a definition for 'Enable' '$$anonymous$$ovingScript.$$anonymous$$yController' does not contain a definition for 'Disable'

Show more comments
Show more comments

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

113 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

Related Questions

Assets/SplashScreen.cs(6,14): error CS1519: Unexpected symbol `public' in cl 1 Answer

is there a way to minimize amount of public items in inspector? 1 Answer

Assign a GameObject to a Component Public Variable using c# 1 Answer

Public and SerializedField's not showing in inspector 1 Answer

I have a little problem getting a component from another script 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