Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Light997 · Jul 05, 2015 at 10:32 AM · c#animationfunction

Calling a function

Hello, I want to call the function Animating in the following script. However, when I save it, I receive these messages:

Assets/Scripts/PlayerController.cs(39,28): error CS0135: h' conflicts with a declaration in a child block Assets/Scripts/PlayerController.cs(39,30): error CS0135: v' conflicts with a declaration in a child block Assets/Scripts/PlayerController.cs(39,17): error CS1502: The best overloaded method match for PlayerController.Animating(float, float)' has some invalid arguments Assets/Scripts/PlayerController.cs(39,17): error CS1503: Argument #1' cannot convert object' expression to type float' Controller 'BlockJumper': Transition '' in state 'ArmatureAction' uses parameter 'IsMoving' which is not compatible with condition type.

The code:


 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     public float speed = 6.0F;
     public float jumpSpeed = 1000.0F;
     public float gravity = 1.0F;
     public float fallSpeed = 2.0F;
     public float h;
     public float v;
     public int stars;
     public Text starText;
     public Text winText;
     public Animator anim;
     
     private Vector3 moveDirection = Vector3.zero;
 
     void Start ()
     {
         SetStarCount ();
         winText.text = "";
     }
 
     void Update() {
 
         CharacterController controller = GetComponent<CharacterController>();
         if (controller.isGrounded) {
             float h = Input.GetAxisRaw ("Horizontal");
             float v = Input.GetAxisRaw ("Vertical");
             moveDirection = new Vector3(h, 0, v);
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
             if (Input.GetButton("Jump"))
                 moveDirection.y = jumpSpeed;
         }
         moveDirection.y -= gravity * Time.deltaTime/fallSpeed;
         controller.Move(moveDirection * Time.deltaTime);
         Animating (h,v);
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag ("Star"))
         {
             other.gameObject.SetActive (false);
             stars = stars + 1;
             SetStarCount();
         }
 
         if (other.gameObject.CompareTag ("Finish")) 
         {
             winText.text = "Congratulations! You finished with " + stars.ToString () + " Stars";
         }
 
         if (other.gameObject.CompareTag ("Void")) 
         {
             gameObject.SetActive (false);
         }
     }
 
     void SetStarCount()
     {
         starText.text = "Stars: " + stars.ToString ();
     }
 
 
     void Animating (float h, float v)
     {
             bool walking = h != 0f || v != 0f;
             anim.SetBool ("IsMoving", walking);
     }
 
 }


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
1
Best Answer

Answer by fafase · Jul 05, 2015 at 10:35 AM

You have global v and h and then you declare a new v and h inside Update. Some older compilers would have let you go but modern one rather indicates an error.

In this case, your global v is hidden internally. And the compiler indicates that it might not be intended.

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 Light997 · Jul 05, 2015 at 11:08 AM 0
Share

Thanks! Helped!

avatar image
1

Answer by NoseKills · Jul 05, 2015 at 10:41 AM

The compiler doesn't know what you are trying to pass into the function Animating (h,v); because you have declared variables with the same name as fields and inside Update().

 public float h;
 public float v;
 //and
 float h = Input.GetAxisRaw ("Horizontal");
 float v = Input.GetAxisRaw ("Vertical");

you have to rename the variables or or use this keyword

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

What is the proper way to wait for an Animator Controller to update? 1 Answer

How to add keyframe animation to an imported FBX. 0 Answers

AdjustCurrentHealth 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