#Getting an int I mentioned before

1 messages · Page 1 of 1 (latest)

junior turtle
#
using System.Collections.Generic;
using UnityEngine;

public class Animchange : MonoBehaviour
{
    [SerializeField] Health Health;
    Animator m_Animator;
    // Start is called before the first frame update
    void Start()
    {
        m_Animator = gameObject.GetComponent<Animator>();
    }

    public int Health
    {
        get { return _Health; }
        set
        {
            _Health = value;
            if (_Health == 1)
            {
                m_Animator.SetBool("animbool", true);
            }
        }
    }

    // Update is called once per frame
    void Update()
    {
       
    }
}```
#

I am trying to change the parameter if my health variable form another script changes but there is a problem with public int Health what shoudl I use instead?

amber timber
#

What is the problem with it

junior turtle
#

The type 'Animchange' already contains a definition for 'Health'

amber timber
#

You cannot have two variables with the same name

junior turtle
#

I want to use the same there

#

not different variables

amber timber
#

Then why do you have two variables

#

If you only want one variable, use one variable

junior turtle
#

I get Health from Health script

#

It creates a new

#

I want to use the one I mentioned before

amber timber
#

I have no idea when you have "mentioned" this before

junior turtle
#

[SerializeField] Health Health;

amber timber
#

This is the first time I am seeing this problem. We are not a hivemind on this server. If you explained things to someone else you will have to explain them again

junior turtle
#

I am trying to check if Health variable from Health script changed not to create another one

amber timber
#

Check it in Health

junior turtle
#

health script is in parent

#

this script is in child

amber timber
#

So?

junior turtle
#

I am trying to change the childs animator parameter

amber timber
#

Honestly why does this script even exist at all

junior turtle
#

is there another way?

amber timber
#

This all seems like something Health should do