Why is my vector3 value not changing?

I created a method that checks whether the value of a Vector3 has any zeros and if it does changes them to zero. Heres my code:

using UnityEngine;
using System.Collections;

public class CheckForZero : MonoBehaviour 
{
    public Vector3 Vectvalue;

	// Use this for initialization
	void Start () 
	{
        Vectvalue = new Vector3(0, 0, 0);
        CheckValue(Vectvalue);
	}
	

    void CheckValue(Vector3 vect3)
    {
        if (vect3.x == 0)
            vect3.x = 1;

        if (vect3.y == 0)
            vect3.y = 1;
        
        if (vect3.z == 0)
            vect3.z = 1;
    }
}

The problem is that the value isn’t being assigned to the Vector. So my question is why is my vector3 value not changing?

After the function the values go nowhere. You are simply not plugging them back in to your vector!

Vectvalue = new Vector3(vect3.x,vect3.y,vect3.z);

is the magic line you should place at the end of your function.

After all, vect3 was created in the arguments of the function, so it doesn’t have scope outside the function.

The other way to do it is to use the return of the function

Vectvalue = CheckValue(Vectvalue);

Vector3 CheckValue(Vector3 vect3)
     {

Vector3 returnVar = new Vector3(vect3.x,vect3.y,vect3.z);
		return returnVar;

I’ll let you decide where these fragments go :wink: