Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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