Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mokhan97 · Jan 21, 2015 at 07:29 AM · script error

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zaid87 · Jan 21, 2015 at 08:05 AM 1
Share

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.

avatar image mokhan97 · Jan 21, 2015 at 10:02 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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

Error CS0266: Cannot implicitly convert type `double' to `int'. An explicit conversion exists (are you missing a cast?) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges