Sorry geting a "the namespace<global namespace> already contains a definition for "

Sorry but I seem to be getting that "the namespace already contains a definition for " error concerning the Hovermotor and the Hoveraudio script Here is the master script

using UnityEngine;
using System.Collections;

public class HovertankExitEnterX : MonoBehaviour {
  
    //This Vehicle Information
    Transform thisVehicle;
    HoverMotor myHoverMotor; //Motor Script, this will be whatever your vehicle uses
    HoverAudio myHoverAudio; //Motor Audio Script, this will be whatever your vehicle uses
    GameObject myCamera    ; //Camera for this vehicle
    GameObject playerExitPosition; //Position to put the player on exiting vehicle
    public GameObject myCanvas;//Basic control information
  
    //This is the Player information
    GameObject myPlayer;//UFPS Player game object
    FirstPersonController myController;//UFPS Player controller
    Input myInput;//UFPS Player Input
  
    //State of this vehicle, if we are in the vehicle or not
    bool InThisVehicle=false;
  
  
    void Start ()
    {
        //Set references to everything
        thisVehicle = this.GetComponent<Transform>();
        myHoverMotor = thisVehicle.GetComponent<HoverMotor>();
        myHoverAudio = thisVehicle.GetComponent<HoverAudio>();
        myCamera = thisVehicle.GetComponentInChildren<Camera>().gameObject;
        playerExitPosition = thisVehicle.FindChild("PlayerExitPosition").gameObject;
      
        //turn off Vehicle scripts and camera on start
        myHoverAudio.enabled=false;
        myHoverMotor.enabled=false;
        myCamera.SetActive(false);
        if(myCanvas)
            myCanvas.SetActive(false);
      
    }
  
    //Exit vehicle keyboard input.  In fixed update so it doesn't move at computer speed
    void FixedUpdate ()
    {
        if(InThisVehicle)
        {
            //Change the Input to whatever you want to use
            if(Input.GetKeyDown(KeyCode.Z))
                ExitVehicle();
        }
      
    }
    public void ExitVehicle()
    {
        myPlayer.SetActive(true);//turn on the player
        myController.SetPosition(playerExitPosition.transform.position);//move the player
        myInput.enabled=true;//enable the player's input
        myHoverMotor.enabled=false;//turn off vehicle stuff
        myHoverAudio.enabled=false;//turn off vehicle stuff
        myCamera.SetActive(false);//turn off vehicle stuff
        InThisVehicle=false;//We aren't in the vehicle anymore
        if(myCanvas)
            myCanvas.SetActive(false);
    }
    public void EnterVehicle()
    {
        myPlayer.SetActive(false);//turn off the player
        myHoverMotor.enabled=true;//turn on vehicle stuff
        myHoverAudio.enabled=true;//turn on vehicle stuff
        myCamera.SetActive(true);//turn on vehicle stuff
        InThisVehicle=true;//We are in the vehicle now
        if(myCanvas)
            myCanvas.SetActive(true);
    }
  
    //Make sure your trigger collider is big enough for the player to interact
    //Also, make sure the Exit position is outside the trigger area
    void OnTriggerEnter(Collider other)
    {
        //if a player enters trigger and the player isn't already in the vehicle
        //just in case there are multiple players
        if(other.gameObject.tag=="Player"&&InThisVehicle==false)
        {
            myPlayer=other.gameObject;//Get the player
            myController=myPlayer.GetComponent<FirstPirstPersonController>();//Get the controller
            myInput=myPlayer.GetComponent<Input>();//Get the input
            EnterVehicle();//Run the EnterVehicle function
        }
    }
}

And here sre the subscripts

using UnityEngine;
using System.Collections;

public class HoverAudio; MonoBehaviour {

    public AudioSource jetSound;
    private float jetPitch;
    private const float LowPitch = .1f;
    private const float HighPitch = 2.0f;
    private const float SpeedToRevs = .01f;
    Vector3 myVelocity;
    Rigidbody hoverRigidbody;
  
    void Awake ()
    {
        hoverRigidbody = GetComponent<Rigidbody>();
    }
  
    private void FixedUpdate()
    {
        myVelocity = carRigidbody.velocity;
        float forwardSpeed = transform.InverseTransformDirection(carRigidbody.velocity).z;
        float engineRevs = Mathf.Abs (forwardSpeed) * SpeedToRevs;
        jetSound.pitch = Mathf.Clamp (engineRevs, LowPitch, HighPitch);
    }
  
}
using UnityEngine;
using System.Collections;

public class HoverMotor : MonoBehaviour {
  
    public float speed = 90f;
    public float turnSpeed = 5f;
    public float hoverForce = 65f;
    public float hoverHeight = 3.5f;
    private float powerInput;
    private float turnInput;
    private Rigidbody hoverRigidbody;

    // System vars
    bool grounded;
    Vector3 moveAmount;
    Vector3 smoothMoveVelocity;
    float verticalLookRotation;
    float MovePosition;
    Transform cameraTransform;
  
    void Awake ()
    {
        hoverRigidbody = GetComponent <Rigidbody>();
    }
  
    void Update ()
    {
        powerInput = Input.GetAxis ("Vertical");
        turnInput = Input.GetAxis ("Horizontal");
    }
  
    void FixedUpdate()
    {
        Ray ray = new Ray (transform.position, -transform.up);
        RaycastHit hit;
      
        if (Physics.Raycast(ray, out hit, hoverHeight))
        {
            float proportionalHeight = (hoverHeight - hit.distance) / hoverHeight;
            Vector3 appliedHoverForce = Vector3.up * proportionalHeight * hoverForce;
            hoverRigidbody.AddForce(appliedHoverForce, ForceMode.Acceleration);
        }
      
        hoverRigidbody.AddRelativeForce(0f, 0f, powerInput * speed);
        hoverRigidbody.AddRelativeTorque(0f, turnInput * turnSpeed, 0f);
        Vector3 localMove = transform.TransformDirection(moveAmount) * Time.fixedDeltaTime;
        hoverRigidbody.MovePosition(GetComponent<Rigidbody>().position + localMove);
        Vector3 localMove = transform.TransformDirection(moveAmount) * Time.fixedDeltaTime;
        hoverrigidbody.MovePosition(hoverrigidbody.position + localMove);
    }
}

These are scripts I downloaded from the Hover In and Out vehicles Youtube example just stuck on this one so far help please

You probably have the Hover Audio script duplicated in your project, somewhere.

Oh OK thank youBenZed

1 Like

You were right BenZed thank you but now getting a “FirstPersonController does not contain a definition for set position” error

In the ExitVehical method, I see this line:

        myController.SetPosition(playerExitPosition.transform.position);//move the player

As the error says, the object of type myController does not contain a definition for SetPosition.

If you copied this code from elsewhere, I’d say it was written with a different (likely older) version of the FirstPersonController component. If you’re using unity 5, try the controller from 4.6x, and vice versa.

Or figure out a way to duplicate what that code was trying to do:

myController.transform.position = playerExitPosition.transform.position;

Would be a likely candidate.

Oh OK thank you I will try that out thanks Ben

OK thanks got it to load up but now I can’t get into the vehicle and the vehicle script won’t disable

Are you sure that the code looks like this:

public class HoverAudio; MonoBehaviour {

?!

1 Like

Well yeah and it runs, just it doesn’t do what it is supposed to do which let the player get into the hover tank and drive it

The code I posted has a ; instead of a : which should produce a syntax error…

OK Ben I will try that thanks I will have to repair my Win XP machine as that is not running properly and get a new second hand graphics card as the one I got in there ( an old Geforce 64MB) Dosen’t have support for shader 1 only shader 0 I would like to get a 1 gb AGP card but they seem to be rare either that or an old 1 GB PCI graphics card that can use the old PCI slots in my HP machine then I could use Unity 4.0 upwards I got Unity 4.6 on there so probably use that

Hi Dantus is it your code then? I think I corrected back Not sure I will check it

Oh I changed it to : as it did produce a syntax error