- Home /
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