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 rushil791 · Apr 23, 2016 at 12:56 PM · errorvariablesonclick

My Script just won't work at all?

My script is designed so when a button is clicked, the sprite will move 45 degrees. when another button is clicked, the same sprite will move -45 degrees. The scripit has no errors but the variable wont show up in the onclick funtion of the button? Please help. Here is my script: using UnityEngine; using System.Collections;

 public class PlatformBehaviour : MonoBehaviour {
 
 
     /* ATTACH THIS AS A CHILD TO "Platform" gameObject*/
     public float turnSpeed = 40f;
     public ControlScript control;
     private float currentAngle;
 
     void Start()
     {
 
         control = GetComponent<ControlScript>(); //this references the ControlScript so you can use it for the rest of the script
         currentAngle = 0f;    
     }
 
     void Update(){
   if (control.currentAngle >= control.maxBlueAngle && control.currentAngle <= control.maxRedAngle) 
     FixedUpdate();
 }      
 void FixedUpdate()
 {
     Turn();
 }
 
     void Turn(){
         float turn = control.InputValue * turnSpeed * Time.deltaTime;
   Quaternion rotation = Quaternion.Euler(0f, 0f, turn);
 
     }
 }
 





 using UnityEngine;
 using System.Collections;
 
 public class ControlScript : MonoBehaviour {
 
 
     public float maxBlueAngle = -45f;
     public float maxRedAngle = 45f;
     public int InputValue;
     public int currentValue;
     public float currentAngle;
     void Start(){
         currentValue = 0;
     }
 
     void BlueRotate(){
         currentValue = -1;
         currentAngle -= 1f;
     }
 
     void RedRotate(){
 
         currentValue = 1;
         currentAngle += 1f;
 
     }
 
Comment
Add comment · Show 1
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 Soraphis · Apr 23, 2016 at 01:01 PM 0
Share

dont call FixedUpdate() from your Update() method. FixedUpdate is called automatically from unity. dont use FixedUpdate at all for non-physical-things. it won't give you any benefit.

from your code: ControlScript->InputValue is always 0 so your Turn-method will always compute turn = 0

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Basakot · Apr 25, 2016 at 08:22 PM

Did you try to attach the script to an empty gameObject? Then attach the empty gameObject to the onClick function?

Comment
Add comment · 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
0

Answer by rushil791 · Apr 27, 2016 at 05:20 PM

@basakot yeah but the variable wouldn't show up in the onclick function :(

Comment
Add comment · 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

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

cannot convert double to int when trying to increment another script's variable by 0.10 1 Answer

Cant access variables outside of On Click() function 1 Answer

Error CS1525: Unexpected symbol 'else' 1 Answer

onClick.AddListener IndexOutOfRangeException error and listener not seen in inspector 0 Answers

DropDown Menu in Vs Code 2020 isn't appearing 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