Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question How to move a simple 2d object

Discussion in 'Animation' started by rc5435922, Dec 5, 2020.

  1. rc5435922

    rc5435922

    Joined:
    Jun 6, 2020
    Posts:
    29
    The simplest code in the world is not working.
    The skull does not move.
    Why?
    Could you give me a solution?

    Image:

    https://ibb.co/0r58MQn

    That's my simple code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class skullspeed : MonoBehaviour
    6. {
    7.     public int speed;
    8.    
    9.     void Update()
    10.     {
    11.         transform.Translate(Vector3.forward * speed * Time.deltaTime);
    12.     }
    13. }
     
  2. rc5435922

    rc5435922

    Joined:
    Jun 6, 2020
    Posts:
    29
    I find the solution. The solution is use Vector2. Because is a 2d game and the Vector3 doesn"t work.
     
    BrandyStarbrite likes this.
  3. KingedKimed

    KingedKimed

    Joined:
    Nov 18, 2020
    Posts:
    7
    Please help. I am making a game, and using simalar code and it keeps telling me I am missing a } but I can't find it.
    Heres the code:
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class MovementScript : MonoBehaviour
    7. {
    8.     public float speed = 15;
    9.    
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.        
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if(Input.GetKey(KeyCode.D))
    20.         {
    21.             transform.Translate(Vector2.Right * speed * Time.FixedDeltaTime);
    22.         }
    23.     }
    24. }
    25.  
    26.  
     
    Last edited: Dec 11, 2020