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 Jasph · Nov 29, 2021 at 10:51 PM · animationscripting problembuild-error

Runs in editor but not in build,works in editor but fails in build mode

So I've got this code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class PlayerControl : MonoBehaviour
 {
     Rigidbody2D body;
     public float movespeed = 5f;
     float x;
     float y;
     //Sprite inserts
     SpriteRenderer sprite;
     public Sprite idle;
     public Sprite walk;
     public Sprite attack1;
     public Sprite attack2;
     public Sprite attack3;
     public Sprite hurt;
     //Timers & things for walk animation
     private bool walking;
     public int walkTimeStart = 300;
     public int walkTime = 0;
     public int walkTimeEnd = -300;
     //Timers & things for attack;
     //private bool attacked;
     private bool hit1;
     private bool hit2;
     private bool hit3;
     public int attackTimeStart = 300;
     public int attackTime = 0;
     // Start is called before the first frame update
     void Start()
     {
         body = GetComponent<Rigidbody2D>();
         sprite = GetComponent<SpriteRenderer>();
         sprite.sprite = idle;
         walkTime = walkTimeStart;
         walking = false;
         //attacked = false;
         hit1 = false;
         hit2 = false;
         hit3 = false;
     }
 
     // Update is called once per frame
     void Update()
     {
         // Movement
         x = Input.GetAxisRaw("Horizontal");
         y = Input.GetAxisRaw("Vertical");
         body.velocity = new Vector2(x * movespeed, y * movespeed);
         if (Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d"))//walking animation
         {
             walkTime -= 1;
             walking = true;
             if (walkTime >= 0)
             {
                 sprite.sprite = walk;
             }
             else if (walkTime <= 0 && walkTime >= walkTimeEnd)
             {
                 sprite.sprite = idle;
             }
             else if (walkTime <= walkTimeEnd)
             {
                 walkTime = walkTimeStart;
             }
         }
         else
         {
             walking = false;
         }
 
         //Flipping
         if (Input.GetKey("a"))
         {
             sprite.flipX = true;
         }
         else if (Input.GetKey("d"))
         {
             sprite.flipX = false;
         }
 
         //Attack
         if (Input.GetKeyDown("v"))
         {
             attackTime = attackTimeStart;
             //attacked = true;
         }
         else if (Input.GetKeyUp("v"))
         {
             //attacked = false;
             hit1 = true;
         }
         if (attackTime >= 0 && hit1 == true)
         {
             
             attackTime -= 1;
             
             if(hit2 == false & hit3 == false)
             {
                 sprite.sprite = attack1;
             }
             if(Input.GetKeyDown("v") && hit2 == false && hit3 == false)
             {
                 hit2 = true;
                 
             }
             else if(Input.GetKeyDown("v") && hit2 == true && hit3 == false)
             {
                 hit3 = true;
             }
             if(hit2 == true && Input.GetKeyUp("v") && hit3 == false)
             {
                 sprite.sprite = attack2;
                 attackTime = attackTimeStart;
             }
             else if (hit2 == true && Input.GetKeyUp("v") && hit3 == true)
             {
                 sprite.sprite = attack3;
                 attackTime = attackTimeStart;
             }
         }
         if (walking == false && attackTime <= 0+1)
         {
             hit1 = false;
             hit2 = false;
             hit3 = false;
             sprite.sprite = idle;
         }
     }
         
 }

which runs fine in the editor, but when I use it in build in run the walk animation only plays one sprite and the attack animation doesn't reset.

Anyone know what's going on?

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

0 Replies

· Add your reply
  • Sort: 

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

130 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

Related Questions

Technique to synchronize during of animation and wanted action? 0 Answers

How to make the animation run longer or shorter? 1 Answer

animation problem 1 Answer

Playing the right animation when running and not running 0 Answers

My animation is not playing 2 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