Cannot implicitly convert type 'int' to 'UnityEngine.Vector3'

Hi,

I have recently started to use Unity, and since I’m not a C# expert, I had some problems.

I want to make a car go from behind a building to another building, and loop that so when the car reaches the building, it teleports to the original building to do the same path again and again…

The problem is that I don’t know how to express ‘When it reaches X position’ without getting an error. The error happens at line 13.
Also, I noticed I can’t put Space.World in Transform.Traslate (it says * isn’t a valid operator for Vector3 and Space). Why?

CODE:

using UnityEngine;
using System.Collections;

public class FixedPath : MonoBehaviour {

	private Transform transform;
	
	void Start() {

	}
	// Update is called once per frame
	void Update () {
        if(transform.forward = -32) {
			transform.Translate(Vector3.forward * Time.deltaTime);
		}
		else {
			transform.forward = -27;
		}
			
	}
}

I’m sorry for being a noob, i know it’s boring to answer stupid questions.

Thanks!

transform.forward is a vector point forward in world space, so it has three numbers x,y,z. For your task, you want to check and change the position of the object. Something like:

void Update () {
    if(transform.position.z > -27.0f) 
        transform.position.z = -32.0f;

    transform.Translate(Vector3.forward * Time.deltaTime);
}

As for ‘Space.World,’ I would have to see the exact line of code that generated the error. You likely tried to multiple rather than put in a comma.

this:

if(transform.forward = -32)

must be

if(transform.forward == -32)

Transform.forward is a Vector3 containing the forward vector for that transform; it can’t be an int like “-32”. Space.World is an enum and can’t be used in math operations like that. See the code examples in the docs for Translate for the exact syntax. Also, you should not have a private variable called “transform”. That already exists by default, and means “gameObject.transform”.