Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

im new to javascript

A topic by Cartersupergames created Aug 10, 2021 Views: 191 Replies: 6
Viewing posts 1 to 6
(2 edits)

hi i am very new to writing javascript and i cant get the right code from google and stuff so i am going to need some help can anyone help me out please?

could you describe your problem?

what is your problem?

Deleted 2 years ago

i need to make a basic movement script in C#

help me please

(1 edit)

(if u don't wanna understand then scroll to very bottom.)

first declare 

public int Xspeed ;

public int Xspeed;

//above start method this'll allow you to access it in inspector, btw you can name it anything

then,

if(Input.GetKey("up")){

transform.position += new Vector3(0,Yspeed,0)*Time.deltaTime;
}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Input.GetKey()

//replace key with any key name such as "up" ,"down" ,"left", "right "

Vector3 

//Vector3 is a class/object that take 3 arguments x,y,z  you can access these values by using dot next to it (dot syntax)

transform.position 

//It's also a bit like Vector3 .When you'll click on your object you can see transform in inspector and under that you'll find position. If you'll change x y z values object will move and this is what we're doin' from script.

time.deltaTime

//if you won't multiply with time.deltaTime then it might not run on 60 fps at all devices.

here's the script copy paste it




using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour

{   

    public float Xspeed;

    public float Yspeed;

    // Start is called before the first frame update

    void Start()

    {

    }

    // Update is called once per frame

    void Update()

    {

        if(Input.GetKey("down")){

            transform.position+=new Vector3(0,-Yspeed,0)*Time.deltaTime;

        }

        if(Input.GetKey("up")){

            transform.position+=new Vector3(0,Yspeed,0)*Time.deltaTime;

        }

        if(Input.GetKey("left")){

            transform.position+=new Vector3(-Xspeed,0,0)*Time.deltaTime;

        }

        if(Input.GetKey("right")){

            transform.position+=new Vector3(Xspeed,0,0)*Time.deltaTime;

        }

    }

}

//btw remember to drag it on you object and then change value of Xspeed and Yspeed from inspector.

Submitted

Check out some of Brakeys tutorials on Youtube, they're a godsend.