Search Unity

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

Discussion in 'Scripting' started by Vampyr_Engel, Aug 4, 2015.

  1. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Sorry but I seem to be getting that "the namespace<global namespace> already contains a definition for " error concerning the Hovermotor and the Hoveraudio script Here is the master script
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class HovertankExitEnterX : MonoBehaviour {
    5.  
    6.     //This Vehicle Information
    7.     Transform thisVehicle;
    8.     HoverMotor myHoverMotor; //Motor Script, this will be whatever your vehicle uses
    9.     HoverAudio myHoverAudio; //Motor Audio Script, this will be whatever your vehicle uses
    10.     GameObject myCamera    ; //Camera for this vehicle
    11.     GameObject playerExitPosition; //Position to put the player on exiting vehicle
    12.     public GameObject myCanvas;//Basic control information
    13.  
    14.     //This is the Player information
    15.     GameObject myPlayer;//UFPS Player game object
    16.     FirstPersonController myController;//UFPS Player controller
    17.     Input myInput;//UFPS Player Input
    18.  
    19.     //State of this vehicle, if we are in the vehicle or not
    20.     bool InThisVehicle=false;
    21.  
    22.  
    23.     void Start ()
    24.     {
    25.         //Set references to everything
    26.         thisVehicle = this.GetComponent<Transform>();
    27.         myHoverMotor = thisVehicle.GetComponent<HoverMotor>();
    28.         myHoverAudio = thisVehicle.GetComponent<HoverAudio>();
    29.         myCamera = thisVehicle.GetComponentInChildren<Camera>().gameObject;
    30.         playerExitPosition = thisVehicle.FindChild("PlayerExitPosition").gameObject;
    31.      
    32.         //turn off Vehicle scripts and camera on start
    33.         myHoverAudio.enabled=false;
    34.         myHoverMotor.enabled=false;
    35.         myCamera.SetActive(false);
    36.         if(myCanvas)
    37.             myCanvas.SetActive(false);
    38.      
    39.     }
    40.  
    41.     //Exit vehicle keyboard input.  In fixed update so it doesn't move at computer speed
    42.     void FixedUpdate ()
    43.     {
    44.         if(InThisVehicle)
    45.         {
    46.             //Change the Input to whatever you want to use
    47.             if(Input.GetKeyDown(KeyCode.Z))
    48.                 ExitVehicle();
    49.         }
    50.      
    51.     }
    52.     public void ExitVehicle()
    53.     {
    54.         myPlayer.SetActive(true);//turn on the player
    55.         myController.SetPosition(playerExitPosition.transform.position);//move the player
    56.         myInput.enabled=true;//enable the player's input
    57.         myHoverMotor.enabled=false;//turn off vehicle stuff
    58.         myHoverAudio.enabled=false;//turn off vehicle stuff
    59.         myCamera.SetActive(false);//turn off vehicle stuff
    60.         InThisVehicle=false;//We aren't in the vehicle anymore
    61.         if(myCanvas)
    62.             myCanvas.SetActive(false);
    63.     }
    64.     public void EnterVehicle()
    65.     {
    66.         myPlayer.SetActive(false);//turn off the player
    67.         myHoverMotor.enabled=true;//turn on vehicle stuff
    68.         myHoverAudio.enabled=true;//turn on vehicle stuff
    69.         myCamera.SetActive(true);//turn on vehicle stuff
    70.         InThisVehicle=true;//We are in the vehicle now
    71.         if(myCanvas)
    72.             myCanvas.SetActive(true);
    73.     }
    74.  
    75.     //Make sure your trigger collider is big enough for the player to interact
    76.     //Also, make sure the Exit position is outside the trigger area
    77.     void OnTriggerEnter(Collider other)
    78.     {
    79.         //if a player enters trigger and the player isn't already in the vehicle
    80.         //just in case there are multiple players
    81.         if(other.gameObject.tag=="Player"&&InThisVehicle==false)
    82.         {
    83.             myPlayer=other.gameObject;//Get the player
    84.             myController=myPlayer.GetComponent<FirstPirstPersonController>();//Get the controller
    85.             myInput=myPlayer.GetComponent<Input>();//Get the input
    86.             EnterVehicle();//Run the EnterVehicle function
    87.         }
    88.     }
    89. }
    And here sre the subscripts
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class HoverAudio; MonoBehaviour {
    5.  
    6.     public AudioSource jetSound;
    7.     private float jetPitch;
    8.     private const float LowPitch = .1f;
    9.     private const float HighPitch = 2.0f;
    10.     private const float SpeedToRevs = .01f;
    11.     Vector3 myVelocity;
    12.     Rigidbody hoverRigidbody;
    13.  
    14.     void Awake ()
    15.     {
    16.         hoverRigidbody = GetComponent<Rigidbody>();
    17.     }
    18.  
    19.     private void FixedUpdate()
    20.     {
    21.         myVelocity = carRigidbody.velocity;
    22.         float forwardSpeed = transform.InverseTransformDirection(carRigidbody.velocity).z;
    23.         float engineRevs = Mathf.Abs (forwardSpeed) * SpeedToRevs;
    24.         jetSound.pitch = Mathf.Clamp (engineRevs, LowPitch, HighPitch);
    25.     }
    26.  
    27. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class HoverMotor : MonoBehaviour {
    5.  
    6.     public float speed = 90f;
    7.     public float turnSpeed = 5f;
    8.     public float hoverForce = 65f;
    9.     public float hoverHeight = 3.5f;
    10.     private float powerInput;
    11.     private float turnInput;
    12.     private Rigidbody hoverRigidbody;
    13.  
    14.     // System vars
    15.     bool grounded;
    16.     Vector3 moveAmount;
    17.     Vector3 smoothMoveVelocity;
    18.     float verticalLookRotation;
    19.     float MovePosition;
    20.     Transform cameraTransform;
    21.  
    22.     void Awake ()
    23.     {
    24.         hoverRigidbody = GetComponent <Rigidbody>();
    25.     }
    26.  
    27.     void Update ()
    28.     {
    29.         powerInput = Input.GetAxis ("Vertical");
    30.         turnInput = Input.GetAxis ("Horizontal");
    31.     }
    32.  
    33.     void FixedUpdate()
    34.     {
    35.         Ray ray = new Ray (transform.position, -transform.up);
    36.         RaycastHit hit;
    37.      
    38.         if (Physics.Raycast(ray, out hit, hoverHeight))
    39.         {
    40.             float proportionalHeight = (hoverHeight - hit.distance) / hoverHeight;
    41.             Vector3 appliedHoverForce = Vector3.up * proportionalHeight * hoverForce;
    42.             hoverRigidbody.AddForce(appliedHoverForce, ForceMode.Acceleration);
    43.         }
    44.      
    45.         hoverRigidbody.AddRelativeForce(0f, 0f, powerInput * speed);
    46.         hoverRigidbody.AddRelativeTorque(0f, turnInput * turnSpeed, 0f);
    47.         Vector3 localMove = transform.TransformDirection(moveAmount) * Time.fixedDeltaTime;
    48.         hoverRigidbody.MovePosition(GetComponent<Rigidbody>().position + localMove);
    49.         Vector3 localMove = transform.TransformDirection(moveAmount) * Time.fixedDeltaTime;
    50.         hoverrigidbody.MovePosition(hoverrigidbody.position + localMove);
    51.     }
    52. }
    These are scripts I downloaded from the Hover In and Out vehicles Youtube example just stuck on this one so far help please
     
    Last edited: Aug 4, 2015
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    You probably have the Hover Audio script duplicated in your project, somewhere.
     
  3. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Oh OK thank youBenZed
     
    BenZed likes this.
  4. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    You were right BenZed thank you but now getting a "FirstPersonController does not contain a definition for set position" error
     
  5. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    In the ExitVehical method, I see this line:

    Code (CSharp):
    1.         myController.SetPosition(playerExitPosition.transform.position);//move the player
    2.  
    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:
    Code (CSharp):
    1. myController.transform.position = playerExitPosition.transform.position;
    Would be a likely candidate.
     
  6. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Oh OK thank you I will try that out thanks Ben
     
  7. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    OK thanks got it to load up but now I can't get into the vehicle and the vehicle script won't disable
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Are you sure that the code looks like this:

    Code (csharp):
    1. public class HoverAudio; MonoBehaviour {
    ?!
     
    Kiwasi likes this.
  9. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    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
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The code I posted has a ; instead of a : which should produce a syntax error...
     
  11. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    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
     
  12. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Hi Dantus is it your code then? I think I corrected back Not sure I will check it
     
  13. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Oh I changed it to : as it did produce a syntax error