Beginner C# problems

Hey all,
I’m having a hard time using C# the way I thought it works, I was hoping someone could steer me in the right direction on this one.
This is a basic script to define a couple variables then utilize those variables.

using UnityEngine;
using System.Collections;

public class CharacterMovement : MonoBehaviour {

public int vertSpeed = 0.20;
public int rotateSpeed = 0.20;

void Update ()
{
if (Input.GetKey (“space”)) {
transform.Translate (Vector3.up * vertSpeed);
}
}
}

When trying to load this back to unity, I receive an error saying
" Constant value 0.2' cannot be converted to a int’ "

If “int” isn’t the right class, what is, and what would be the correct formatting for my use? Thanks all.

Vectors are floats. Start here.

you should watch all the scripting videos once a month for a year. it will make you way way way smarter. I still go back to them from time to time years later. not patronizing. Gametyme is right. There are things you will -not- understand right now you will two months from now, and so on.

and int cannot have a decimal. it is a solid number.
a float is a floating point value, and can have decimals
you want declare

float rotateSpeed = 0.2f;

if you don’t add the f it will be treated as a double and will not work.
read the tutorials. watch the videos. you will save yourself way more time than if you don’t, even if they seem time consuming.

2 Likes

Thanks for the indepth explanation. I will most definately take your advice onboard. These videos are the ones Gametyme has mentioned?

I suggest you, to learn the C# basics. There are ton of online open books. “If “int” isn’t the right class”, That are variables which saving your datas in memory at runtime. ^^

Seems like you just need to learn the basics. You’re driving a car not realising that handbrake and clutch exist :slight_smile:

1 Like

Cars have handbrakes??

Legend has it, they sometimes come with wheels.