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 sandermanderthefirst · Jan 17, 2018 at 09:39 PM · animationerrormovementanimatorcontrols

Controls are not cooperating with me all of a sudden.

I've been working on my project and trying to make the animation and coding work. I added the animations but now all of a sudden, the movement in the player script is all broken and not working.

This is my only script, so there's no other ones I need to publish, if you'd like to see my Animator or anything else like that, let me know.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Player : MonoBehaviour {
 
     //General Variables
     public float speed;
     private Rigidbody2D rb;
     private GameObject sword;
 
     //Class Setting Variables
     public PlayerClassTypes eCurClass = PlayerClassTypes.Tank;
 
     //Animator Variables
     Animator sword_Anim;
 
     void Start () 
     {
         //Sets variables automatically on launch
         sword_Anim = sword.GetComponent<Animator> ();
         sword = GameObject.Find ("Sword");
         rb = gameObject.GetComponent<Rigidbody2D> ();
     }
 
     void FixedUpdate () 
     {
 
         //Making the velocity variables to make 'fake friction'
         Vector3 easeVelocity = rb.velocity;
         easeVelocity.y *= 0.75f;
         easeVelocity.z = 0.0f;
         easeVelocity.x *= 0.75f;
 
         //Sets the variables to move them up and down
         float h = Input.GetAxis ("Horizontal");
         float v = Input.GetAxis ("Vertical");
 
         //Fake Friction / Easing the x speed of our player
         rb.velocity = easeVelocity;
         
         //Moving the player up and down
         rb.AddForce (Vector2.up * speed * v);
         rb.AddForce (Vector2.right * speed * h);
     }
 
     //Sets the Player classes
     public enum PlayerClassTypes
     {
         Tank,
         DPS,
         Healer
     }
 
     //Handles the Tank class
     void HandleTankState ()
     {
         if(Input.GetKeyDown(KeyCode.Space))
             {
             //Starts Sword Swing animation
             sword_Anim.SetBool("swing_Animation", true);
             }
     }
 }
 

The error message I'm getting is "Object reference not set to an instance of an object Player.FixedUpdate () (at Assets/Scripts/Player.cs:30)"

Thanks for looking over my script and any input at all would be very helpful!

Comment
Add comment · Show 2
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 getyour411 · Jan 18, 2018 at 02:16 AM 0
Share

Check to see if you accidentally unchecked the 2D RigidBody component on your Player gameObject.

avatar image sandermanderthefirst getyour411 · Jan 19, 2018 at 08:21 PM 0
Share

I checked the Rigidbody 2D component and it's still enabled

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sandermanderthefirst · Jan 19, 2018 at 09:34 PM

I found out what was wrong. I didn't reference the sword variable correctly and ended up going a different method to calling it.

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

244 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 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

Animation in android game not working 2 Answers

help with animation and movement?,i want to sort out my animation in my movement? 0 Answers

How to add movement to animations? 1 Answer

Help with Animator has not been initialized error 5 Answers

How to make animations match movement direction 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