Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Skimmey · May 10, 2014 at 03:58 PM · animationvariableerror message

variable has not been assigned?

Hi, I'm pretty new to Unity, and I'm trying to design my own video game for a school project. The project has been going well so far, but i keep getting this error, something like... "The variable 'whatever' of 'myscript' has not been assigned, you probably need to assign it in the inspector". But i have put my variable in, is it because its a transform? Oh and this happened when i added my two animation codes, it keeps on spamming me with the same error (but the script still works, and i'm able to play the game perfectly). -my code

 #pragma strict
 
 var TheDamage : int = 50;
 var Distance : float;
 var MaxDistance : float = 1.5;
 var WeaponPipe : Transform;
 function Update () 
 {
     //click
     if (Input.GetButtonDown("Fire1"))
 {
     //animation Attack
     WeaponPipe.animation.Play("Attack");
 
     //function attack
     var hit :RaycastHit;
     if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
     {
     Distance = hit.distance;
     if (Distance < MaxDistance)
     {
     
     hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
     }
     }
 
 }
     if (WeaponPipe.animation.isPlaying == false)
     {
         WeaponPipe.animation.CrossFade("Idle");
     }
 }

-credit goes to the Brackeys tutorial for helping me with the script

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 Scribe · May 10, 2014 at 04:27 PM 0
Share

So you have dragged a transform object onto WeaponPipe in the inspector? if not then you should do that or use a find function in Start (or elsewhere) to set WeaponPipe.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by felixpk · May 10, 2014 at 04:49 PM

If you use public variables you must:

if it is a Transform or whatever:

  • Assign a Transform or whatever in the Inspector

  • or find a reference like:

       void Start () {
             objRef = GameObject.FindGameObjectsWithTag("Player");
         }
    
    

if it is an Integer or float or so

  • you can change the Value in the inspector

  • or declare it like:

    public float x = 20F;

if these are private Variables:

  • make sure you initialized them either when you declared them like above

  • or you inizialise them in Start(), Update() ect.

Hope that clears your problem.

Felix

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 Skimmey · May 11, 2014 at 12:58 PM 0
Share

Thanks, I hope this works, I'll be trying it out on Tuesday. But I have already put it into the inspector which really confuses me as to why I keep getting the same error.

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

22 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

What is it "Input Button 87 is not Setup"? 2 Answers

How to change a variable in the same script? 3 Answers

Get information from variable 1 Answer

What is happening and what does this MEAN!?!?!?!?!?!?!?!? AHHHHH!!!!,WHAT IS HAPPENING?!?! 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