- Home /
What does that mean? "BCW0008: WARNING: Duplicate namespace: 'UnityEngine'"
That is my conde.. What is wrong?
import UnityEngine;
import System;
class PlayerController extends MonoBehaviour
{
var speed = 800.0;
function FixedUpdate() {
var moveHorizontal : float = Input.GetAxis ("Horizontal");
var moveVertical : float = Input.GetAxis ("Vertical");
var movement = Vector3(moveHorizontal, 0.0, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
}
It gives me that Warning "BCW0008: WARNING: Duplicate namespace: 'UnityEngine'" and i cant move my player.
Answer by Landern · Oct 02, 2014 at 02:11 AM
By default using UnityEngine(c#) or import UnityEngine(unityscript) and System.Collection.Generic are automagically added to the top of the script but you don't see it. So yes, it is duplicated since you explicitly added them. Go ahead and remove your import for UnityEngine.
Answer by graviton · Oct 02, 2014 at 03:20 AM
Are you trying to mix Unity Java and C#?
You can't mix Java and C#
import UnityEngine; (Wrong)
import System; (Wrong)
class PlayerController extends MonoBehaviour (Wrong)
var speed = 800.0; (Wrong)
function FixedUpdate (Wrong, this is Java)
I fixed your code, it's in C#
//Make sure you Freeze the X and Z Rotations on the Rigidbody!
//Make sure your script is also called "PlayerController"!
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed = 800f;
void FixedUpdate()
{
float moveVertical = Input.GetAxis("Vertical");
float moveHorizontal = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
}
Your code in Java
#pragma strict
var speed = 800.0;
function FixedUpdate()
{
var moveHorizontal : float = Input.GetAxis ("Horizontal");
var moveVertical : float = Input.GetAxis ("Vertical");
var movement = Vector3(moveHorizontal, 0.0, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
Hope this help
@graviton, the op was using UnityScript(it's not java, it's not javascript, though some syntax is shared, yes it's called JS in the docs, but we know it's not).
The OP code was correct and yes you can create classes in unityscript and yes you can extend(inherit/derive) from other classes. It may look like c# given some of the keywords used, but they are just shared. Take a gander at the tutorials on classes, you don't need to watch the video, just switch the example code to JS(unityscript).
Yes i realize it's marked as JS/JavaScript all over unity's docs and site, but calling it java it taking the confusion a step further. It's agreed it was a poor decision to call it javascript. In monodevelop you create UnityScripts, in the editor you create JavaScript...
@Landern "UnityScript(it's not java, it's not javascript"
I didn't say it was, I know Unity Java is not the same as Java Script, that's why right at the top I wrote "Are you trying to mix Unity Java and C#?", "Unity Java", understand "Unity Java"
"Laurentiu963" didn't state whether he was trying to write his code in Java (yes Unity Script) or C#
I just assumed that he was trying to write a C# script and got mixed up, wrote Java's "import UnityEngine;" but in fact meant to write C#'s "using UnityEngine;"
I think you are way too hung up on all this "Unity Java (Unity Script) shouldn't be called Java" business
You know people here are going to keep calling it Java right?
I have to agree with @landern on this. There's no point having this site designed to help people learn how to use Unity if it contains confusing, inaccurate information. We didn't make the Java/Javascript/Unityscript nomenclature mess, but we shouldn't continue to propagate it unnecessarily.
I'm not so bothered about the Javascript/Unityscript distinction, but Java is a completely different thing. I have seen several questions on this site along the lines of "What is the best book I should buy to help me learn Java for Unity", which is going to lead to a lot of disappointed purchases. It also makes it very hard to identify those occasional questions that really are about Java (e.g. server-side or Android plugins).
inaccurate?
propagate?
I'm not propagating anything
It's like you guys are only reading what you want to hear
Wrong as it may be, Unity are calling it Java here and in the documentation, calling it something else isn't going to change that
Whether you like it or not people here are still going to keep calling it Java
That's enough trolling out of you, this isn't a forum
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to make a GUI.box pop up under an if statement (new to programming) 1 Answer
How to make enemy slowly run to player 1 Answer
How to add play again or quit dialog 1 Answer
CS0029 convert type 1 Answer