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 /
This question was closed Jan 18, 2018 at 02:29 AM by esandberg2000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by esandberg2000 · Jan 18, 2018 at 02:05 AM · scripting problemerror messageanimator controllernewbie

Need Help with Enemy Attack Animation Script? I'm new to Unity.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Enemy1Animation : MonoBehaviour
 {
     Animator anim;
 
     void OnCollisionEnter(Collision col)
     {
         if (col.gameObject.tag == "Player")
         {
             collided = true;
         }
 
         else
         {
             collided = false;
         }
 
         // Use this for initialization
         void Start()
         {
 
             anim = GetComponent<Animator>();
 
         }
 
         // Update is called once per frame
         void Update()
         {
 
             if (collided = true)
             {
                 anim.SetInteger("State", 1);
             }
 
 
 
 
         }
     }
 }
 
 

So this is the code I have- In my animator controller I have an Int Parameter called "State" and conditions on the transitions between walking and attacking in which State must = 0 for walk animation and 1 for attack animation. The image included shows the errors I got after attaching the script to an enemy prefab which also has an Animator Component with the correct Animator Controller. I'm very new to Unity and was relying on a tutorial for Animating my enemies but I can't figure out what I've done to cause these errors- any help would be really appreciated, sorry if this is a really simple thing that I should already know. Like I said, I'm very new to Unity. alt text

errors.jpg (44.0 kB)
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

  • Sort: 
avatar image
0

Answer by bhavinbhai2707 · Jan 18, 2018 at 02:17 AM

  1. You added an extra } (curly braces) at the end, remove that.

  2. The if statement in update method , you are assigning the variable and not comparing , so in order to do that correctly write it with ==

      If(collided == false)
         {
                //Statements
         }
    
     
    
    
    
    
    
Comment
Add comment · Show 2 · 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 esandberg2000 · Jan 18, 2018 at 02:28 AM 0
Share

Thank you!! I forgot the extra = and had a curly brace going to wrong line of text. That fixed it!

avatar image bhavinbhai2707 esandberg2000 · Jan 18, 2018 at 11:00 AM 0
Share

always there to help mate!! keep learning :)

Follow this Question

Answers Answers and Comments

128 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

Related Questions

A get or set accessor expected 1 Answer

How do I attach a script to a state 1 Answer

How do I make a level-to-level loading screen with bar? 1 Answer

cannot drag script to player.Guitext error,cannot drag player script to the player in hierarchy 2 Answers

Having some issues with my Animator Controller. 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