Search Unity

Spaceship Flight Controls

Discussion in 'Scripting' started by Vampyr_Engel, Oct 31, 2018.

  1. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Yes I am trying to write a Spaceship Flight Control ship that will use mouse and keyboard, joypad, Joystick and Joystick H.O.T.A.S controls but I have got stuck on this as I have tried to rarrange several scipts with no success and tried this

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections;
    4. namespace AssemblyCSharpfirstpass
    5. {
    6.        
    7.   public class SpaceshipFlightControls : MonoBehaviour
    8.         {
    9.      
    10.         // Performs a mouse look.
    11.      
    12.      
    13.  
    14.                 public float speed = 10.0f;
    15.                 public float rotationSpeed = 100.0f;
    16.             float horizontalSpeed = 2.0f;
    17.             float verticalSpeed = 2.0f;
    18.          
    19.             void Update()
    20.             {
    21.                 // Get the mouse delta. This is not in the range -1...1
    22.                 float h = horizontalSpeed * Input.GetAxis("Mouse X");
    23.                 float v = verticalSpeed * Input.GetAxis("Mouse Y");
    24.              
    25.                 transform.Rotate(v, h, 0);
    26.             }
    27.         }
    28.         // A very simplistic spaceplane  driving on the xyz plane.
    29.      
    30.  
    31.          
    32.             void Update()
    33.             {
    34.                 // Get the horizontal and vertical axis.
    35.                 // By default they are mapped to the arrow keys.
    36.                 // The value is in the range -1 to 1
    37.                 float translation = Input.GetAxis("Vertical") * speed;
    38.                 float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
    39.              
    40.                 // Make it move 10 meters per second instead of 10 meters per frame...
    41.                 translation *= Time.deltaTime;
    42.                 rotation *= Time.deltaTime;
    43.              
    44.                 // Move translation along the object's z-axis
    45.                 transform.Translate(0, 0, translation);
    46.              
    47.                 // Rotate around our y-axis
    48.                 transform.Translate(0, translation , 0);
    49.             }
    50.        }
    51.   }
    But I keep getting this and I have it 4 tines now
    Assets/SpaceshipFlightControls.cs(50,5): error CS0103: The name `' does not exist in the current context error how do I solve this
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You have two Update() functions and too many braces, prematurely ending your class and leaving code orphaned.

    I'm surprised the errors aren't more specific about that though.
     
  3. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Still getting this error ''a namespace cannot directly contain members such as fields or methods''