Hey,
I would like to make a Flight Simulator. But there is one problem I would like to change the speed with the MouseScroll.
Here is my Script and the variable. Please put it in. Because I’m a Noob
Ps. Sorry for my English I’m from Germany
The Variable:
var speed += Input.mouseScrollDelta * scrollSensitivity;
And my Script:
using UnityEngine;
using System.Collections;
public class Flight : MonoBehaviour {
public float Speed = 90f;
public float scrollSensitivity = 40f;
// Use this for initialization
void Start () {
// Update is called once per frame
void Update () {
var Speed = Input.mouseScrollDelta * scrollSensitivity;
Vector3 moveCamTo = transform.position - transform.forward * 10.0f + Vector3.up * 5.0f;
Camera.main.transform.position = moveCamTo;
Camera.main.transform.LookAt (transform.position);
transform.position += transform.forward * Time.deltaTime * 90.0f;
Speed -= transform.forward.y * Time.deltaTime * 2.0f;
speed = 35.0f;
}
transform.Rotate( Input.GetAxis(“Vertical”), 0.0f, -Input.GetAxis(“Horizontal”) );
float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight( transform.position );
if (terrainHeightWhereWeAre > transform.position.y) {
transform.position = new Vector3(transform.position.x,
terrainHeightWhereWeAre,
transform.position.z);
}
}
}
mgear
December 3, 2019, 8:19am
2
so what is the problem, speed doesnt change?
also note that you have this variable:
public float Speed = 90f;
and then another variable with same name:
var Speed = Input.mouseScrollDelta * scrollSensitivity;
and then line 25-26 its speed with lowercase s.
mgear:
so what is the problem, speed doesnt change?
also note that you have this variable:
public float Speed = 90f;
and then another variable with same name:
var Speed = Input.mouseScrollDelta * scrollSensitivity;
and then line 25-26 its speed with lowercase s.
What help me I’m a noob
No and yes speed doesn’t change and there is a Error
MilchBrocken:
Ok is this right?
Code:
using UnityEngine;
using System.Collections;
public class Flight : MonoBehaviour {
var Speed = Input.mouseScrollDelta * scrollSensitivity;
public float scrollSensitivity = 40f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var Speed = Input.mouseScrollDelta * scrollSensitivity;
Vector3 moveCamTo = transform.position - transform.forward * 10.0f + Vector3.up * 5.0f;
Camera.main.transform.position = moveCamTo;
Camera.main.transform.LookAt (transform.position);
transform.position += transform.forward * Time.deltaTime * 90.0f;
Speed -= transform.forward.y * Time.deltaTime * 2.0f;
if(speed < 35.0f){
speed = 35.0f;
}
transform.Rotate( Input.GetAxis(“Vertical”), 0.0f, -Input.GetAxis(“Horizontal”) );
float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight( transform.position );
if (terrainHeightWhereWeAre > transform.position.y) {
transform.position = new Vector3(transform.position.x,
terrainHeightWhereWeAre,
transform.position.z);
}
}
}
Dude, use code tags please. Its really difficult to read code formatted like this.
Here is code tag:
using UnityEngine;
using System.Collections;
public class Flight : MonoBehaviour {
public float Speed = 90f;
public float scrollSensitivity = 40f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var Speed = Input.mouseScrollDelta * scrollSensitivity;
Vector3 moveCamTo = transform.position - transform.forward * 10.0f + Vector3.up * 5.0f;
Camera.main.transform.position = moveCamTo;
Camera.main.transform.LookAt (transform.position);
transform.position += transform.forward * Time.deltaTime * 90.0f;
Speed -= transform.forward.y * Time.deltaTime * 2.0f;
if(speed < 35.0f){
speed = 35.0f;
}
transform.Rotate( Input.GetAxis("Vertical"), 0.0f, -Input.GetAxis("Horizontal") );
float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight( transform.position );
if (terrainHeightWhereWeAre > transform.position.y) {
transform.position = new Vector3(transform.position.x,
terrainHeightWhereWeAre,
transform.position.z);
}
}
}
mgear
December 3, 2019, 11:38am
7
can you copy the error code from console?
mgear
December 3, 2019, 11:44am
9
and if you double click it, it should take you to that line where error is.
i’m guessing its that line 24, you have not defined that “speed” variable anywhere.
(its not same as “Speed”, more info )