Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help me please!!!!

Discussion in 'Scripting' started by MilchBrocken, Nov 28, 2019.

  1. MilchBrocken

    MilchBrocken

    Joined:
    Nov 5, 2019
    Posts:
    33
    Ok I have a question I would like make a Game but there is one thing. Its a Flight Simulator and I would like to make a adjustable Speed but I don't everything about this. The Speed changes with the Mouse Well

    Ps. Im German my Englisch isnt good. Sorry for that ;)
     
  2. ShadowAngel

    ShadowAngel

    Joined:
    Aug 7, 2012
    Posts:
    12
    You will need to add to your player controller method Update, and inside it add
    Code (CSharp):
    1. var speed += Input.mouseScrollDelta * scrollSensitivity;  
    Then just set scrollSensitivity somewhere and use speed for your character.
     
  3. MilchBrocken

    MilchBrocken

    Joined:
    Nov 5, 2019
    Posts:
    33
    Thank you so much I will try this in few seconds. Oh one thing Method Update? Did you mean "void Update"?

    If you help me in my other Thread I love you link below #nohomo

    https://forum.unity.com/threads/teleport-skill.783521/
     
    Last edited: Nov 29, 2019
  4. MilchBrocken

    MilchBrocken

    Joined:
    Nov 5, 2019
    Posts:
    33
    Ok i have write my code and that shows like this please help me again <3
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Flight : MonoBehaviour {
    5.  
    6.     public float Speed = 90f;
    7.     public float scrollSensitivity = 40f;
    8.  
    9. // Use this for initialization
    10. void Start () {
    11.    
    12. }
    13.  
    14. // Update is called once per frame
    15. void Update () {
    16.     var Speed = Input.mouseScrollDelta * scrollSensitivity;
    17.     Vector3 moveCamTo = transform.position - transform.forward * 10.0f + Vector3.up * 5.0f;
    18.     Camera.main.transform.position = moveCamTo;
    19.     Camera.main.transform.LookAt (transform.position);
    20.  
    21.     transform.position += transform.forward * Time.deltaTime * 90.0f;
    22.  
    23.     Speed -= transform.forward.y * Time.deltaTime * 2.0f;
    24.  
    25.     if(speed < 35.0f){
    26.     speed = 35.0f;
    27. }
    28.  
    29. transform.Rotate( Input.GetAxis("Vertical"), 0.0f, -Input.GetAxis("Horizontal") );
    30.  
    31. float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight( transform.position );
    32.  
    33. if (terrainHeightWhereWeAre > transform.position.y) {
    34.     transform.position = new Vector3(transform.position.x,
    35.                                     terrainHeightWhereWeAre,
    36.                                     transform.position.z);
    37. }
    38. }
    39. }