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 /
avatar image
0
Question by Claymstamper · May 19, 2016 at 04:56 AM · unity 5scripting problemaccessing

Why is my debug log not going through? (Trying to get a script to access a non static variable of another script.)

I'm not getting any parser errors and everything should be working fine. Below I'll post the script with the message that is failing to log and below that will be part of the script that I'm trying to access. Thank you for any help you can provide!

using UnityEngine; using System.Collections;

public class Sombrero : MonoBehaviour {

 public GameObject Player;

 void Start() {
    
 }

 void update() {
    GameObject thePlayer = GameObject.Find("Triangle");
    PlayerController playerscript = thePlayer.GetComponent<PlayerController>();
     if (playerscript.health == 5) {
         Debug.Log("Low HP");
     }
 }

}

using UnityEngine; using System.Collections;

And here is the list of variables from my player controller that I'm trying to access. My goal here is to add a function to my sombrero game object when the health reaches a certain point.

public class PlayerController : MonoBehaviour {

 public float speed = 5f;
 public float bumper;
 float xmin;
 float xmax;
 public GameObject taco;
 float projectileSpeed = 15f;
 public float fireRate = 5f;
 public float health = 5f;

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jdean300 · May 19, 2016 at 05:09 AM

Unless what you posted has a typo, your update function needs a capital "U" to be automatically called by Unity.

If you don't know how to use the debugger, I suggest you read this and learn to use it - it'd make finding this type of problem very easy: https://unity3d.com/learn/tutorials/modules/beginner/scripting/monodevelops-debugger

Comment
Add comment · 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 Claymstamper · May 19, 2016 at 02:46 PM 0
Share

Yeah the U in Update was just a typo. And I actually don't use $$anonymous$$ono develop. I was never able to get $$anonymous$$ono to work so I use something called $$anonymous$$icrosoft visual studio.

avatar image Bonfire-Boy · May 19, 2016 at 04:12 PM 0
Share

So does it work after fixing the typo?

If not, what is the value of health in the PlayerController (in the inspector)?

avatar image jdean300 · May 19, 2016 at 05:09 PM 0
Share

Visual Studio - even better. Figure out the debugger. Basically, click on the left side of the code window to place a breakpoint, click the green play button at the top the attach the debugger to unity, then play your game in the Unity editor. Your programs execution will stop wherever you placed your breakpoint (so place it at this update function), and you can see what is wrong by hovering your mouse over various variables.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why isn't my animation state changing properly? 1 Answer

Switch vehicle 1 Answer

I am not able to reload a Scene a second time for my game 0 Answers

API Update ruined my scripts 1 Answer

Is unity uses rendering from the cpu or gpu ? 2 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