Is Unityscript/JavaScript Discontinued

Is Unityscript/Javascript discontinued?

According to some comments on the Unity forums:

One user said back in February, "UnityScript has already been abandoned. Just no one has told the marketing team yet."

Then just today (at the time of this post), a Unity representative replied,
"UnityScript will continue to work in 2017.2. We removed the menu item because we would like to avoid new users picking it up, but you can still add new UnityScript files to your project by other means" (emphasis mine).

So there we have it. UnityScript is (likely) being removed and this is the first step: preventing new users from starting with it.

Can I use Java script language in Unity3d 2017.2?

Yes, you can still use it in Unity 2017.2. The menu to create a Javascript script is gone. You have to create a Javascript file with an external file Editor like Notepad then drag it into your Unity project and it should just work. It should have .js extension.

Note that Unity is in the process of stripping the Javascript compiler out of Unity Editor so you won't be able to use Javascript in the future. See this post for more information.

Read mouse click Input.GetMouseDown with Unityscript

There are just many issues with your first code.

1.The code is not inside a function. That should be in the Update function.

2.You are missing extra ) in the if statement since there should be one ) for the GetMouseDown function and another one that closes the if statement.

3.The mySlider variable is not declared. You manged to declare that in the counter script but not in your first script.

import UnityEngine.UI;
import UnityEngine.EventSystems;

var mySlider:Slider;

function Update(){

if(Input.GetMouseDown(0)){
// Whatever you want it to do.
ScoreSystem.drinks -= 1;

mySlider = GameObject.Find("water").GetComponent(UnityEngine.UI.Slider);
counter.water = counter.water += 10;
mySlider.value = counter.water;
}
}

Note:

It is always good to capitalize the first letter in your class/script name. For example, counter should be Counter and your variable names should start with lower-case. This will make it easier for people to read and understand your code.

Finally, convert all your scripts to C#. You will have to do this ASAP so that you won't have to restart your project over again when the Unityscript compiler is removed.

Problems building unity code for android

Because Android doesn't support dynamic typing.
In this line of code:

var name = obj.gameObject.name;

name is declared as a generic variable, without the specific type.
Windows, during the compilation phase, let it pass, but Android will not.
It should be:

var name : String = obj.gameObject.name;

Two hints:

1) [recommended] Start learning C#, it's more robust, efficient and better supported.

2) If you'd like to continue with the UnityScript path, add #pragma strict at the beginning of every script of yours. This force the compiler to apply the strict rules as in Android, preventing dynamic typing (compilation errors will arise on Windows as it would be on Android).

Why is it SO Hard to Just Mute a Sound in Unity?

Your mute code is fine.

"UnityException: GetComponentFastPath is not allowed to be called from
a MonoBehaviour constructor (or instance field initializer), call it
in Awake or Start instead. Called from MonoBehaviour 'motioncheck' on
game object 'Ball'." I'm not sure what this means, since I'm still
kinda a nub at JavaScript.

See this:

var audioSource = GetComponent.<AudioSource>();

That's a Unity API and you have to call their functions from inside a function. The Awake or Start function is appropriate for initializing component variables.

var audioSource : AudioSource;
function Start()
{
audioSource = GetComponent.<AudioSource>();
}

Note that Unityscript/Javascript is now discontinued. They no longer update the doc on this and you cannot create new scripts from the Editor anymore. It still works as for now but the compiler will be removed soon. Please learn and start using C# before its support is totally removed.

Using PointerEventData returns error: Unexpected symbol

There are a few things you should review in your code:

The Vector2.MoveTowards() is not being called with the proper parameters. GameObject.Find() will return a gameObject, not a Vector2. If you're looking for the current position of player 1, you should construct a Vector2 from player 1's transform.position.

Vector2 playerPosition = new Vector2();
playerPosition.x = GameObject.Find("player-1").transform.position.x;
playerPosition.y = GameObject.Find("player-1").transform.position.y;

Any use of PointerEventData requires a using directive for EventSystem. In order to include it, add using UnityEngine.EventSystem with the rest of your using directives.

The Vector2 prefix before PointerEventData.position() is invalid. It's not an explicit typecast, as it's not in parenthesis, but typecasts aren't needed since position will return a Vector2.

pointerEventData.position is a property that draws from an object reference. However, the implementation of PointerEventData.position() is improperly using this as a static method. Since it's not actually a static method, but a dynamic property, it will fail to compile and draw errors.

For pointerEventData to exist, it needs to originate from an event which retrieves eventData. Unfortunately, OnMouseDown() does not do this. However, an interface method from IPointerClickHandler called OnPointerClick(PointerEventData pointerEventData) has the pointerEventData you need.

Refactoring your existing code, this is closer to the functionality you're looking for.

// Add this "using" directive
using UnityEngine.EventSystems;

// Be sure to implement the interface of IPointerClickHandler
public class NameOfYourScript : MonoBehaviour, IPointerClickHandler {

//
// Additional Code in your class. . . .
//

// Replace OnMouseDown() with this.
public void OnPointerClick(PointerEventData pointerEventData) {
Instantiate(bullet_player);

Vector2 playerPosition = new Vector2();
playerPosition.x = GameObject.Find("player-1").transform.position.x;
playerPosition.y = GameObject.Find("player-1").transform.position.y;

Vector2.MoveTowards(playerPosition, pointerEventData.position, p1BulletSpeed);
}
}


Related Topics



Leave a reply



Submit