Error CS1729 the type UnityEngine.Vector3 does not contain a constructor that takes 4 arguments and 1 more...
I have this error and another error: ERROR CS1612 cannot modify a value type return value of UnityEngine.Transform.position consider storing the value in a temporary variable.
Code: using UnityEngine; using System.Collections;
public class SwimmingScript : MonoBehaviour {
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (this.transform.position.y < -1.4)
{
this.gameObject.transform.position.y = new Vector3(transform.position.x, -1.4f, transform.position.z, -1.4f);
}
}
}
I really need help :(
this.gameObject.transform.position = new Vector3(transform.position.x, -1.4f, transform.position.z);
Answer by Landern · Sep 17, 2015 at 12:42 PM
Best to use a copy of your transform.position Vector3 since it has all but one of the values you want. Vector3 doesn't have a constructor that takes 4 arguments/parameters as the exception stated, it takes a new Vector3, or x and y or x, y and z.
void Update()
{
if (this.transform.position.y < -1.4)
{
Vector3 tempTransform = this.gameObject.transform.position; // get a copy of the current position, we only want to change one value.
tempTransform.y = -1.4f; // x and z are not changed, lets only change the y value.
this.gameObject.transform.position = tempTransform;
}
}
Note: if you're going to use the keyword 'this' while coding, make sure you're consistent about it as it appears you used it multiple times (if statement and the setting of the position), but stopped using it when setting the x and z values of the Vector3. If you're referring to the current instance of an object, this is to remove confusion about what you're referring to and also isolate same named variables that exist in inherited classes.
Your answer
![](https://koobas.hobune.stream/wayback/20220612034057im_/https://answers.unity.com/themes/thub/images/avi.jpg)