- Home /
error CS1729
Hi, my script won't work the error, 'error CS1729: The type UnityEngine.Vector2' does not contain a constructor that takes 3' arguments' pops up. all i want to do is make my player spawn and move. Here's the script:
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public float playerSpeed = 5.0f;
// Use this for initialization
void Start () {
//Player spawn point
//This is where the player will start when the game is payed.
//Player = Game Object. Game Object = Transform
transform.position = new Vector2(-2.5,-0.32,0);
}
// Update is called once per frame
void Update () {
//player to move up/left/right/down
//player (gameobject) aka transform to move when i press the arrow keys
transform.Translate (Vector2.right * Input.GetAxis ("Horizontal") * playerSpeed * Time.deltaTime);
transform.Translate (Vector2.up * Input.GetAxis ("Vertical") * playerSpeed * Time.deltaTime);
}
}
Thank you
This line
transform.position = new Vector2(-2.5,-0.32,0);
if it's Vector2, it will only takes 2 value. The last value (0) shouldn't be there.
Thank you for all of your responses, my game was a top-down, third-person game such as Corpse Party. When I changed my values in the animator, i used this final script:
using UnityEngine; using System.Collections;
public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour { public float speed;
private Animator _animator;
private Rigidbody2D _rigidbody2D;
void Start ()
{
_animator = GetComponent <Animator> ();
_rigidbody2D = GetComponent <Rigidbody2D> ();
}
void Update ()
{
CheckDirection ();
}
void CheckDirection ()
{
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A))
{
WalkAnimation (-1, 0, true);
}
else if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.D))
{
WalkAnimation (1, 0, true);
}
else if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W))
{
WalkAnimation (0, 1, true);
}
else if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.S))
{
WalkAnimation (0, -1, true);
}
else
{
_animator.SetBool ("Walking", false);
}
}
void FixedUpdate ()
{
$$anonymous$$ove ();
}
void $$anonymous$$ove ()
{
float dirX = _animator.GetFloat ("VelX");
float dirY = _animator.GetFloat ("VelY");
bool walking = _animator.GetBool ("Walking");
if (walking)
{
_rigidbody2D.velocity = new Vector2 (dirX, dirY) * speed;
}
else
{
_rigidbody2D.velocity =Vector2.zero;
}
}
void WalkAnimation (float x, float y, bool walking)
{
_animator.SetFloat ("VelX", x);
_animator.SetFloat ("VelY", y);
_animator.SetBool ("Walking", walking);
}
}
P.S it's a 2D game.
Answer by ramp · Jan 21, 2015 at 11:41 AM
Hello,
Replace the code line 10,and use Vector3 instead of Vector2,like this.
transform.position = new Vector3(-2.5f,-0.32f,0f);
Thanks
Ram
Your answer
Follow this Question
Related Questions
What's Wrong With This Script? 1 Answer
Object reference not set to an instance of an object. 0 Answers
Script is causing crashes and i Don't know what to do. 2 Answers
NullReferenceException 0 Answers