Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Resolved Scene Change Animation Error

Discussion in 'Animation' started by GeorgeSaint, Mar 19, 2021.

  1. GeorgeSaint

    GeorgeSaint

    Joined:
    Aug 16, 2018
    Posts:
    8
    Hello!
    My game uses UnityStandardAssets.CrossPlatformInput it is mobile game but:
    So i have player with attached to him sword
    in scene one, keyboard attack of weapon works fine, animation fine, and UI button, of that same attack works fine, animation works fine.
    I cloned that scene, renamed it and press run:
    First scene all right, player moves, keyboard attack works, animation work, UI attack works and the animation work too.
    Moving to scene two(cloned from first)
    Player moves, keyboard attack works fine, animation perfect, when i press the UI button(same attack like keybord) Error:

    The variable anim of Weapon has not been assigned.

    How it can be? keyboard controls works fine,animation of attack perfect, but UI button give me error of ANIMATION????
    Thank You!

    My weapon script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Weapon : Collidable
    6. {
    7.     //Damage structure
    8.     public int[] damagePoint = {1,2,3,4,5,6,7 };
    9.     public float[] pushForce = { 1.5f, 2.0f, 2.5f, 3f, 3.2f, 3.6f, 4f};
    10.  
    11.     //Upgrade
    12.     public int weaponLevel = 0;
    13.     private SpriteRenderer spriteRenderer;
    14.  
    15.     //Swing
    16.     private Animator anim;
    17.     private float cooldown = 0.5f;
    18.     private float lastSwing;
    19.  
    20.     private void Awake()
    21.     {
    22.         spriteRenderer = GetComponent<SpriteRenderer>();
    23.     }
    24.     protected override void Start()
    25.     {
    26.         base.Start();
    27.         anim = GetComponent<Animator>();
    28.     }
    29.  
    30.     protected override void Update()
    31.     {
    32.         base.Update();
    33.  
    34.         if (Input.GetKeyDown(KeyCode.Space))
    35.         {
    36.             if (Time.time - lastSwing > cooldown)
    37.             {
    38.                 lastSwing = Time.time;
    39.                 Swing();
    40.             }
    41.         }
    42.     }
    43.  
    44.     protected override void OnCollide(Collider2D coll)
    45.     {
    46.  
    47.         if (coll.tag == "Fighter")
    48.         {
    49.             if (coll.name == "Player")
    50.                 return;
    51.  
    52.             // Damage to object with TAG Fighter
    53.             Damage dmg = new Damage
    54.             {
    55.                 damageAmount = damagePoint[weaponLevel],
    56.                 origin = transform.position,
    57.                 pushForce = pushForce[weaponLevel]
    58.             };
    59.  
    60.             coll.SendMessage("ReceiveDamage", dmg);
    61.         }
    62.     }
    63.  
    64.     public void Swing()
    65.     {
    66.         anim.SetTrigger("Swing");
    67.     }
    68.     public void UpgradeWeapon()
    69.     {
    70.         weaponLevel++;
    71.         spriteRenderer.sprite = GameManager.instance.weaponSprites[weaponLevel];
    72.  
    73.         //Change stats
    74.     }
    75.  
    76.     public void SetWeaponLevel(int level)
    77.     {
    78.         weaponLevel = level;
    79.         spriteRenderer.sprite = GameManager.instance.weaponSprites[weaponLevel];
    80.     }
    81. }
    82.  
     
  2. GeorgeSaint

    GeorgeSaint

    Joined:
    Aug 16, 2018
    Posts:
    8
    Yeah)
    i figure out that problem
    it all was prefab of player & weapon
    separated they are very different who knew))
    "Closed"
     
unityunity