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 /
This question was closed Sep 18, 2016 at 08:17 PM by lexmcnevan for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by lexmcnevan · Jul 18, 2016 at 09:47 PM · scripting problemscripting beginnerscriptingproblemscripterror

Script error

Hi, I'm creating a game and I have a problem with one of the Scripts. This is the script and there are the two errors, any idea of how i can fix it? This is a script to get my chatacter to attack and get back to the Idle position. alt text

attack.png (174.6 kB)
Comment
Add comment · Show 9
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 oskar2771 · Jul 18, 2016 at 10:23 PM 0
Share

Can you copy the code and put it there plz ?

avatar image lexmcnevan oskar2771 · Jul 19, 2016 at 12:26 AM 0
Share

Okay so I have this right now: public class Attack2 : $$anonymous$$onoBehaviour { protected Animator animator;

 // Use this for initialization
 void Start()
 {
     animator = GetComponent<Animator>();
 }
 // Update is called once per frame
 // Update is called once per frame
 void Update()
 {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0))
     {
         animator.SetBool("Attack", true);
     }
     else {
         animator.SetBool("Attack", false);
     }
 }

}

it's perfect, no errors, but now I click on the left button and nothing happens. I think the code is O$$anonymous$$ so idk what's wrong. $$anonymous$$y animator tree is set with a variable type Bool called Attack which goes from idle to Attack when true and comes back when false...

avatar image joshua-lyness oskar2771 · Jul 19, 2016 at 02:33 AM 0
Share

Ive never tried your method for getting mouse buttons. The mouse buttons actually have their own special input, Input.Get$$anonymous$$ouseButton. There's also a variation, Get$$anonymous$$ouseButtonDown, and Get$$anonymous$$ouseButtonUp. Then you specify which button. (0) for left button, (1) for right button, and (2) for middle. All in all, it looks something like this:

 if(Input.Get$$anonymous$$ouseButton(0)){
 
 }
avatar image joshua-lyness oskar2771 · Jul 19, 2016 at 02:38 AM 0
Share

Still, your code seems fine and should still run. Is your script attached to an object? Is the animator set up properly? Put Debug.Log("true") inside the if statement to see if the code ever runs. If so, it's not a problem with the script.

Show more comments
avatar image lexmcnevan · Jul 18, 2016 at 10:28 PM 0
Share

Sure! There it is: using UnityEngine; using System.Collections;

public class Attack2 : $$anonymous$$onoBehaviour { protected Animator animator;

 // Use this for initialization
 void Start() {
     animator = GetComponent<Animator>();

 }

 // Update is called once per frame
 // Update is called once per frame
 void Update() {
     if (Input.GetButton("$$anonymous$$ouse0"));
     {
         animator.SetBool("Attack", true);
     }
     else {
         animator.SetBool("Attack", false);
     }
 }

}

avatar image oskar2771 lexmcnevan · Jul 18, 2016 at 10:32 PM 1
Share

using UnityEngine; using System.Collections;

public class Logo : $$anonymous$$onoBehaviour { protected Animator animator;

 // Use this for initialization
 void Start()
 {
     animator = GetComponent<Animator>();
 }
 // Update is called once per frame
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButton("$$anonymous$$ouse0")) 
     {
         animator.SetBool("Attack", true);
     }
  else {
         animator.SetBool("Attack", false);
     }
 }

}

avatar image oskar2771 lexmcnevan · Jul 18, 2016 at 10:34 PM 0
Share

Don't use ; after (). if (Input.GetButton("$$anonymous$$ouse0")); {...} NO if (Input.GetButton("$$anonymous$$ouse0")) {...} O$$anonymous$$

avatar image joshua-lyness lexmcnevan · Jul 18, 2016 at 11:21 PM 0
Share

It would be more useful if you added the error messages as code too, but yea the problem is your semi colon on your if statement.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

76 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

Related Questions

How do i make an uppercut attack? 0 Answers

Why does material.setColor not work when used in another function?, 1 Answer

Set public gameobject by raycast hit target 1 Answer

How to reassign a new script reference to the same variable that previously had the same script with another reference? 0 Answers

Help with Changing the Sprite image in the Script 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