Search Unity

Item - Inventory System Action RTS infinite load !

Discussion in 'Scripting' started by Ohz_fr, Apr 20, 2021.

  1. Ohz_fr

    Ohz_fr

    Joined:
    Jan 3, 2020
    Posts:
    22
    Hey hi!
    Here I am doing a game rtS style I like the system of free asset!
    Item - Inventory System
    Especially for the resource harvesting system!
    But voila I have a problem at the level of a scipte action!
    I would love to be able to play the animation on the unit that interacts with the item or resource!
    The asset and super well F***ed and can create action!
    Unfortunately I row at the level of the scipte! It makes me an infinite load!
    I thought I'd put a componnent on the unit! Target unit .
    But a scipte pauses me problem I post you the innitial scipte and change it!
     
  2. Ohz_fr

    Ohz_fr

    Joined:
    Jan 3, 2020
    Posts:
    22
    innitial scipte

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

    namespace DevionGames
    {
    [UnityEngine.Scripting.APIUpdating.MovedFromAttribute(true, null, "Assembly-CSharp")]
    [Icon(typeof(Animator))]
    [ComponentMenu("Animator/CrossFade")]
    public class CrossFade : Action
    {
    [SerializeField]
    private TargetType m_Target= TargetType.Player;
    [SerializeField]
    private string m_AnimatorState = "Pickup";
    [SerializeField]
    private float m_TransitionDuration = 0.2f;

    private Animator m_Animator;
    private int m_ShortNameHash;

    public override void OnStart()
    {
    this.m_ShortNameHash = Animator.StringToHash(this.m_AnimatorState);

    this.m_Animator = this.m_Target == TargetType.Self ? gameObject.GetComponentInChildren<Animator>() : playerInfo.animator;
    }

    public override ActionStatus OnUpdate()
    {
    if (m_Animator == null)
    {
    Debug.LogWarning("Missing Component of type Animator!");
    return ActionStatus.Failure;
    }
    this.m_Animator.CrossFadeInFixedTime(this.m_ShortNameHash, this.m_TransitionDuration);
    return ActionStatus.Success;
    }
    }
    infinite load scipt


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

    namespace DevionGames
    {

    [ComponentMenu("Animator/CrossFadeUnit")]
    public class CrossFade : Action
    {
    [SerializeField]
    public TargetUnit d_target;
    [SerializeField]
    private string m_AnimatorState = "Pickup";
    [SerializeField]
    private float m_TransitionDuration = 0.2f;
    [SerializeField]
    private Animator m_Animator;
    [SerializeField]
    private int m_ShortNameHash;
    public override void OnStart()
    {
    this.m_ShortNameHash = Animator.StringToHash(this.m_AnimatorState);
    this.m_Animator = this.d_target != null ? playerInfo.animator : gameObject.GetComponentInChildren<Animator>();
    }





    public override ActionStatus OnUpdate()
    {
    if (m_Animator == null)
    {
    Debug.LogWarning("Missing Component of type Animator!");
    return ActionStatus.Failure;
    }
    this.m_Animator.CrossFadeInFixedTime(this.m_ShortNameHash, this.m_TransitionDuration);
    return ActionStatus.Success;
    }
    }
    }