0

hi want to access the public vector value NewMax in another script and modify the x value

using UnityEngine;
using UnityEngine.Events;

namespace Lean.Common
{
    /// <summary>This component allows you to convert 1, 2, or 3 values from one range to another. For example, an angle in the range of -90..90 could be converted to 0..1. This is done by calling one of the <b>SetX/Y/Z</b> methods, and then sending it out using the <b>OnValueX/Y/Z</b> events.</summary>
    [HelpURL(LeanHelper.PlusHelpUrlPrefix + "LeanRemapValue")]
    [AddComponentMenu(LeanHelper.ComponentPathPrefix + "Remap Value")]
    public class LeanRemapValue : MonoBehaviour
    {
        [System.Serializable] public class FloatEvent : UnityEvent<float> {}
        [System.Serializable] public class Vector2Event : UnityEvent<Vector2> {}
        [System.Serializable] public class Vector3Event : UnityEvent<Vector3> {}

        

        /// <summary>The range of the input values.</summary>
        public Vector3 OldMin { set { oldMin = value; } get { return oldMin; } } [SerializeField] private Vector3 oldMin;

        /// <summary>The range of the input values.</summary>
        public Vector3 OldMax { set { oldMax = value; } get { return oldMax; } } [SerializeField] private Vector3 oldMax = Vector3.one;

        /// <summary>The range of the output values.</summary>
        public Vector3 NewMin { set { newMin = value; } get { return newMin; } } [SerializeField] private Vector3 newMin;

        /// <summary>The range of the output values.</summary>
        public Vector3 NewMax { set { newMax = value; } get { return newMax; } } [SerializeField] private Vector3 newMax = Vector3.one;
    }
}

when I tried this from another script

public void voltageFlowCheck() //meter
    {    Lean.Common.LeanRemapValue.NewMax.x=2;
         Amount_of_Voltage_Passing_out = Lean.Common.LeanFormatString.Qapp_value; 
               }

I got the following error :-

Vector3 Lean.Common.LeanRemapValue.NewMax { get; set; } The range of the output values.

An object reference is required for the non-static field, method, or property 'LeanRemapValue.NewMax' [Assembly-CSharp]csharp(CS0120)

how can I fix this and get the value? And is there any way to call it using gameobject.GetComonent<>()

1
  • Your class/variables are not static. So you must reference an instance Commented Mar 30, 2022 at 13:14

1 Answer 1

2

First, you have to get the GameObject that the LeanRemapValue class is attached to, and then with `.GetComponent().NewsMax you get the value and can modify it.

You can get the GameObject in the editor or with the GameObject.Find() method.

If a script inherits from MonoBehaviour it has to be attached to a GameObject and then the script acts as a component. .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.