//Now we can multiply vectors by numbers
//meaning we nolonger treat the time as constant
public class MeteorAttack : MonoBehaviour
{
public Vector velocity = new Vector(5, 0);
Point meteorPosition;
// Use this for initialization
void Start()
{
meteorPosition =
new Point(transform.position.x, transform.position.y);
}
// Update is called once per frame
void Update()
{
meteorPosition = meteorPosition + Time.deltaTime * velocity;
transform.position =
new Vector3(meteorPosition.x, meteorPosition.y);
}
}
public class Point
{
public static Point operator +(Point a, Point b)
{
Point result =
new Point(a.x + b.x, a.y + b.y);
return result;
}
public float x, y;
public Point()
{
x = 0; y = 0;
}
public Point(float x, float y)
{
this.x = x;
this.y = y;
}
//NoLonger Useful
//public Point AddVector(Vector b)
//{
//Point c = new Point();
//c.x = this.x + b.x;
//c.y = this.y + b.y;
//return c;
//}
}
[System.Serializable]
public class Vector
{
public static Vector operator *(float m, Vector a)
{
Vector result = new Vector(a.x, a.y);
result.x = result.x * m;
result.y = result.y * m;
return result;
}
public static implicit operator Point(Vector v)
{
return new Point(v.x, v.y);
}
public float x, y;
public Vector()
{
x = 0; y = 0;
}
public Vector(float x, float y)
{
this.x = x;
this.y = y;
}
}
This is initially made for Jordan Game Dev Magazine Episode 03
feel free to use it any way, any how any form you like.
feel free to use it any way, any how any form you like.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.