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 /
  • Help Room /
avatar image
0
Question by Technokid2000 · Jan 01, 2018 at 06:26 AM · unity 5scripting problemnot working

C# Script not working as expected

Hi,

I have been working with unity for a while, but have recently thought about making a game. So, as you can guess, I tried to make one. It was working well for a while. However, as soon as I started expanding on one of my scripts by adding health and stamina, it stopped noticing that the script was there. Unity was picking up that the script was there and I was changing it, but for some reason it wasn't applying anything I did, to the point where a normal print() statement in the Awake() function wouldn't do anything. I can remove the parts that make my player move, and the player will stop moving as expected, but trying to add a run feature, a health bar, stamina bar, or even print() no longer works.

The whole script is very large, but you can mimic the issue I'm having by trying the following script:

 using System.Collections;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Player_Controller : MonoBehaviour {
     public float walkingSpeed = 0.15f;
     public float runningSpeed = 0.15f;
     public float jump_height = 10.0f;
     public float strongGravity = -30.0f;
     public float weakGravity = -9.81f;
     public bool lockJump_Active = false;
     public bool disableDoubleJump = false;
     public bool ignoreStamina = false;
 
     private bool Can_Jump = false;
     private float Translation;
     private float Straff;
     private float stamina = 100;
     private float health = 100;
 
     private CharacterController controller;
     public Rigidbody rb;
     public Slider healthSlider;
     public Slider staminaSlider;
 
     void Awake () {
         //First testing to see if script is running
         print ("Update");
         Debug.Log ("update");
 
         Cursor.lockState = CursorLockMode.Locked;
         controller = GetComponent<CharacterController> ();
     }
 }


I know it is a lot for just 1 script (and there is much MUCH more that I have excluded), but I can't figure out what I have done wrong. I have tried removing component then adding it again, I have tried restarting Unity, but nothing seems to work.

I am using Unity 2017.1.0f3 on a windows 7 64 bit system.

Thanking all of you in advance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Technokid2000 · Jan 01, 2018 at 06:40 AM

Not entirely sure what I did, but the script is now working quite nicely, apart from print() and Debug.Log() functions which for some reason still aren't working. I realised that I never set the min/max values for the sliders (which I have now fixed), and also that running speed should have been set to 0.25f, not 0.15f, which was the same as walking speed. So most of my issues have been fixed, but does anyone know why print() still isn't working?

My new (almost) working script is below:

 using System.Collections;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Player_Controller : MonoBehaviour {
     public float walkingSpeed = 0.15f;
     public float runningSpeed = 0.25f;
     public float jump_height = 10.0f;
     public float strongGravity = -30.0f;
     public float weakGravity = -9.81f;
     public bool lockJump_Active = false;
     public bool disableDoubleJump = false;
     public bool ignoreStamina = false;
 
     private bool Can_Jump = false;
     private float Translation;
     private float Straff;
     private float stamina = 100;
     private float health = 100;
 
     private CharacterController controller;
     public Rigidbody rb;
     public Slider healthSlider;
     public Slider staminaSlider;
 
     void Awake () {
         //First testing to see if script is running
         print ("Starting Script - print");
         Debug.Log ("Starting Script - debug.log");
 
         healthSlider.maxValue = 100;
         staminaSlider.maxValue = 100;
         healthSlider.minValue = 0;
         staminaSlider.minValue = 0;
         Cursor.lockState = CursorLockMode.Locked;
         controller = GetComponent<CharacterController> ();
     }
 }

Am I missing something obvious with the print() and Debug.Log() functions?

Again, thanking you all in advance.

Comment
Add comment · 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 Technokid2000 · Jan 02, 2018 at 02:02 AM 0
Share

In the end, I found the issue. I had turned off info and warnings from the console without realising. The only thing still active was errors, which I found by doing:

 Debug.LogError("error");

Then, I turned on info and warnings. To anyone having the same issue, try that. A link to a post that explains it better is here: https://answers.unity.com/questions/530784/console-doesnt-work.html

avatar image
0

Answer by brenttonkgames · Jul 14, 2020 at 04:14 PM

c# is not working i use visual studio c# for unity i was following along with a tutorial i did the code right and i had nothing but errors somebody please help me

Comment
Add comment · 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 Technokid2000 · Jul 15, 2020 at 02:26 AM 0
Share

Please put this as a seperate thread. For people to be able to help you, please post the code you are attempting to use, as well as the actual errors you are having. This is like saying "$$anonymous$$y car won't work, help!" without actually saying what part of the car isn't working, the symptoms, what you've tried, what car you actually have, etc. Please don't necro an old thread, because you won't get a problem solved that way. Seperate new problem, seperate new thread

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

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

How do I make this script actually load the level 1 Answer

My movement script is not moving my 2D object 2 Answers

Camera Help 0 Answers

how do i keep an item destroyed when i change the scene c# 0 Answers

How too climb a ladder with the FPS Controller correctly 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