Hi,
I’m missing some functionality in the Vector2 class, for example the normalized getter as in:
Vector2.normalized
How could I extend the existing class Vector2 with a getter? Is it possible in JS?
Any help greatly appreciated -
Jörg (first time poster)
Vector2 is not a class but a struct.
As for extending it, you could write a static function in your class that will take a Vector2 in parameter and return the normalized vector… ?
By the way, if you want a getter/setter there is way.
I don’t know how to do it in JS but here is how it works in C#
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
private string m_test;
void Start () {
m_test = "";
}
// Update is called once per frame
void Update () {
}
public string MyTest
{
get { return m_test; }
set { m_test = value; }
}
}
Now you can use:
Test t = new Test();
t.MyTest = "Hello, World!";
Debug.Log(t.MyTest);
Hope it helps.
Scrat, many thanks for your replies.
Seems it’s not possible to use getters/setters in JS …
I’ll try your code in C#