unityscript

How to activate a script from another object?

夙愿已清 提交于 2019-12-13 09:34:18
问题 I'm trying to activate a script from another object on a button press. Heres what I tried: function Update () { if(Input.touchCount == 1) { GameObject.Find("theobject").GetComponent(thescript).enabled = true } else { GameObject.Find("theobject").GetComponent(thescript).enabled = false } } When I press play, It has no errors but when I press the button, nothing happens. Are there anything wrong with the script. I'm new to Unity and Javascript. Any help would be appreciated. Thanks in advanced!

How to infinite loop numbers in while loops? (Unity3D- unityscript)

我的梦境 提交于 2019-12-13 05:44:03
问题 function OnMouseDown () { rotationNumber +=1; } function Update () { while (rotationNumber == 1) { gameObject.GetComponent(SpriteRenderer).sprite = leftArrow; return; } while (rotationNumber == 2) { gameObject.GetComponent(SpriteRenderer).sprite = upArrow; return; } while (rotationNumber == 3) { gameObject.GetComponent(SpriteRenderer).sprite = rightArrow; return; } while (rotationNumber == 4) { gameObject.GetComponent(SpriteRenderer).sprite = upArrow; rotationNumber = 1; return; } } I want to

How to develop a scrollview with inertia in Unity?

浪子不回头ぞ 提交于 2019-12-13 04:23:31
问题 I want to develop a "scrollview" in Unity. Basically I have a Parent Game Object on the screen with many items inside it. The Parent Game Object is big enough so it goes outside the screen. I developed a scrolling script so when the user drags the parent object, I move it and it looks like scrolling. I did this by implementing the OnMouseDrag event. How can I calculate the inertia and apply it so when the user drags it fast, it continues to move? 回答1: What you want, the effect that you want,

Unity 2D: PlayerPrefs Implementation for Highscore

本小妞迷上赌 提交于 2019-12-13 03:45:55
问题 I need some assistance implementing a HighScore that saves. Currently, I have a score, which starts from 500,000 and gets down 150 points per seconds. This works, although when I die it still goes on, which I need to fix. I have a second kmHighscore Text, and I want it to show the highscore. Right now it shows the exact score on which I died(for example 450,875), but when I restart the game I can't seem to make it be saved. I tried with PlayerPrefs, but I am not sure how to apply it in my

error CS0246: The type or namespace name `CharacterMotor' could not be found. Are you missing an assembly reference?

微笑、不失礼 提交于 2019-12-13 03:23:20
问题 I have script from book (Sams Teach Yourself Unity Game Development in 24 Hours) which I cannot compile its keep trowing me error I add all missing Assembly reference but its still cannot find something. here is assembly from visual studio here is code using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityStandardAssets.Characters.FirstPerson; public class GameControlScript : MonoBehaviour { //The amount of ellapsed time private float time = 0; //Flags that control the

Displaying variables using gui in Unity

那年仲夏 提交于 2019-12-13 02:15:22
问题 In my game, I want a button that when clicked on, overwrites a string. This string will then be displayed in some text above. So far it is going very wrong... Here is the code ( in C#) that I use: using UnityEngine; using System.Collections; public class ConnectGUI : MonoBehaviour { private string map = "No map selected."; // Use this for initialization void Start () { } void OnGUI () { GUI.Label(new Rect(10,10,200,90), "Map selected: ", map); if(GUI.Button (new Rect(10,50,90,20), "Pier")){

Activity of android above default lock screen using unity c# scripts

浪尽此生 提交于 2019-12-13 01:06:56
问题 how i can add WindowManager 's LayoutParams flag inside unity c# scripts. For example i can do it in Android by code as follow. getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 回答1: you can do that like this: AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>(

Save sound value PlayerPrefers

落花浮王杯 提交于 2019-12-12 05:08:02
问题 I have a UI MENU where the player can set the volume of the game music. Through a slider it can change the volume. I'm trying to save these values, and retrieves them whenthe game is open again, but without success so far. When we change the value of the Slider, the sound also changes, but these values are not being saved. My code looks like this: Ps: 0 warning in Unity console, and C# answer if possible =] using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine

Unity transform.LookAt in only one axis

倖福魔咒の 提交于 2019-12-12 03:57:25
问题 I've been working on a game and it's going really nice. Got some help from here and I need it again. So I'm making a 2D top-down shooter and I need my enemy to look at the player, and obviously the enemy will rotate in all axis and thus being invincible or will look really weird. So, how do I make it rotate only in the Z axis ? Also if you are going to provide and answer I need it done in UnityScript. 回答1: You just need to set a fixed value at the axis that you don't want to move. Example,

UI Canvas Start - Quit Game

a 夏天 提交于 2019-12-12 03:25:20
问题 I have 2 Canvas UIs (Start and Exit) on the home screen of my game. I want to add 1 script that does the following: When the UI Image Play is clicked public void NextLevel(int level) { Score.Inicializar(); Application.LoadLevel (1); } When the UI Image Exit is clicked Application.Quit () ; C# if possible. 回答1: Add this script to your Play image: using UnityEngine; using UnityEngine.EventSystems; //using UnityEngine.SceneManagement; // uncomment this line in case you wanna use SceneManager