So i’ve been trying to figure this out for 3hours now and I cant figure it out.
My idea is that I have this cube . and when I push it a distance away from it’s original position. It destroys itself. But I got a problem. I think im on to something, but I dont know how to fix this error
(If Im doing this completely wrong, Tell me. I havent used C# ever before , and Im trying to figure this out…)
using UnityEngine;
using System.Collections;
public class BreakableObject : MonoBehaviour {
[HideInInspector] int startPosX;
[HideInInspector] int startPosY;
[HideInInspector] int startPosZ;
public Vector3(float x, float y , float z) // Error here. (Must have Return type)
// Use this for initialization
void Start () {
startPosX = Vector3.x;
startPosY = Vector3.y;
startPosZ = Vector3.z;
}
// Update is called once per frame
void Update () {
if ((Vector3.x ^ Vector3.y ^ Vector3.z) < (startPosX ^ startPosY ^ startPosZ))
{
Object.Destroy (this.gameObject);
}
if ((Vector3.x ^ Vector3.y ^ Vector3.z) > (startPosX ^ startPosY ^ startPosZ))
{
Object.Destroy (this.gameObject);
}
}
}
however, you’ll need to use float’s and not int’s if you want any sort of accuracy/it to work at all
and when you’re comparing, you need to think about what you’re testing against - your Vector3 being greater/less than something isn’t (usually) practical.
what are you trying to achieve here? two positions not being (approximately) equal?
for your future sanity, might i suggest you run through a few of the unity tutorials - they’re a good introduction to unity & c# and should help you get more familiar with the syntax.