FAQ Database Discussion Community


Unity3D Bullet Tracers

unity3d,unityscript,raycasting
I'm currently working on implementing the elusive bullet tracer to my FPS. It isn't going so well. a. The tracers align themselves off of the barrel of the Raycast area b. They all aim themselves in the same direction, no matter where I point my cursor This is the formula...

Unity Javascript help on Stop and resume function

unity3d,unityscript
I have the below code in Unity JS. What I need is when function Count1 is called, function CountTime stops and starts again. Similar with function Count2 and Count3. But when function Count4 is called, CountTime should stop and not resume again. #pragma strict import UnityEngine.UI; private var textfield:Text; private...

Jump to another scene detecting a rigidbody

c#,unityscript
I am making a little game in c# on unity 5, and until now I have almost everything. How do I jump to another scene on detecting a rigidbody?

How to use AddForce and Velocity together?

c#,unity3d,game-physics,unityscript
I have the jump component who use the AddForce for jumping and the movement component who move left and right using the Velocity. If you don't move the character when your are jumping the jumping will be fine but when you move the character and jump at the same time...

If raycast is not hitting an object - change the material color to white

javascript,user-interface,unity3d,unityscript
I am working on a small school project in Unity for my IT classes. I've created a script in Unityscript that shows specific GUI when the raycast hits and object with certain tag. I also want it to change the material color to yellow as soon as the raycast hits...

Why do you need to attach or reference and object when accessing another class variable in unity?

c#,unity3d,unityscript
For example, If i want to access the integer health in another class, i have to create a reference off that class and attach it to an object either in the inspector or programatically. How come i cannot just access the public integer without attaching the object? Example code public...

Parent object not accessing variables from children's script

unity3d,triggers,artificial-intelligence,unityscript
I'm working on a project in Unity and I've created a script called DeerHater that targets the transform and controller of an object that enters the specified area. The script by itself works but it's connected to a parent object that has it's controller attached and that controller is supposed...

Cropped Label due to Big Font

c#,android,user-interface,unity3d,unityscript
I've got this problem : The text in the label is cropped. This is my code: public var MenuSkin:GUISkin; function OnGUI () { GUI.skin = MenuSkin; GUI.skin.font = myfont; GUI.Label ( new Rect (Screen.width-310,Screen.height/2,300,50), "Number is 16"); } The label is cropped. How do i fix it without changing the...

function won't run in unityscript

unity3d,unityscript,unity3d-2dtools
I new to unityscript and am making a platformer game in Unity 2D but my character Movement script won't work. I assume that the function isn't being called but it used to work. this is the code: #pragma strict var JumpSpeed : float = 10; var walkSpeed : float =...

How to access variable in JS script from C# script?

c#,unity3d,unityscript
I have a game on Unity3d and I write scripts using JS (UnityScript) and C#. In the JS script I have a variable, which I need to access in the C# script. Is it possible to do something like this? Script.js: public var myVarible; Script.cs: class A { void B()...

How to convert data in unityscript

unity3d,unityscript
Now I have data like this "1234567890", first it is System.Object I want convert it to long. I tried like this (long) data data as long data as System.Int64 It seems they all not work,anyone can help me?...

How to delete new'd arrays in JavaScript?

javascript,arrays,new-operator,unityscript,delete-operator
I'm using Unity, so this is technically UnityScript but I assume the built-in arrays work the same way. I have an array I create thusly: var room:roomInfo[,,]; room=new roomInfo[5,5,5]; What's the deleting syntax? Simply doing delete room; or delete room[,,]; doesn't seem to work. After deleting it I need to...

Unity ads not working on android device

unity3d,unityscript
imported unity ads asset from unity asset store. This asset working well when imported a new project. I have a game project and still working on this project. Imported a asset store like a previous. Ads working well on unity player but not working on android device. Logcat output is...

OnTriggerEnter2D not working Unity3d (JavaScript)

unity3d,triggers,unityscript
Dear sctackoverflow Community, I've got a problem with the onTriggerEnter2D function in unity3D, since it's not working, and at the same time, I'm not aware of what is going wrong. Note that I have searched this problem in other forums and threads, and none of the solutions would work for...

playing an animation in landscape mode in unity

unity3d,unityscript
i am trying to play an animation in landscape mode in unity but as soon as the game start the phone turn in landscape mode and it quit without playing anything i have only one scene with a UI Image contain an animator and a simple animation this is the...

Changing sprites using Sprite.Create does not take effect?

unity3d,sprite,unityscript,gameobject,unity3d-2dtools
I'm making minecraft-like 2D game and everything seems like it's okay except changing block texture in one chunk. This is how I try to change sprite: var block = new GameObject("blok", typeof(SpriteRenderer), typeof(BoxCollider2D), typeof(CircleCollider2D)); block.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("/Prefabs/Blokovi/blok_zemlja") as Texture2D, Rect(0, 240, 16, 16), Vector2(0.5, 0.5), 16); It does not take...

changing unity layout group childForceExpand with code

javascript,unity3d,unityscript
I am just wondering how to access the child Force Expand of the layout groups with code. I'm attaching Vertical layout groups to instantiated panels and want to turn the force expand off.

Disable item after 10 shots

unity3d,unityscript
How can I disable an object after you press 10 times the left mouse button? This is the script that I'm using, but does not work very well. #pragma strict var myTrigger : GameObject; var myObject : GameObject; var countAmmo : int = 10 ; function Start() { } function...

Is it possible to make the Unity3D UI slider that follows a timeline?

c#,time,unity3d,slider,unityscript
Basically is it possible to create a slider that works like the slider present in youtube videos with the pause and play button. The concept for me is to link the slider so that it moves according to a timeline. The play and pause buttons would then just be used...

Change Material in MeshRenderer

unity3d,unityscript
I have a number of materials in my project and there paths are listed as followed: Assets/3DModels/Materials/01 - white.mat Assets/3DModels/Materials/02 - black.mat Assets/3DModels/Materials/03 - red.mat Assets/3DModels/Materials/04 - green.mat Assets/3DModels/Materials/05 - blue.mat Assets/3DModels/Materials/06 - purple.mat I also have some 3D models created using 3ds max and imported into Unity. The models...

Are Update's serialized or parallelized?

unity3d,unityscript
I'm new to Unity5, and I'm trying to create a simple game. By extending MonoBehaviour, I receive an Update() function. But I don't know how it works behind the scenes. My question is, are the Update() functions serialized (called one after the other) or parallelized when many MonoBehaviours have their...

new tag not working

unity3d,unityscript
im having trouble figuring out whats wrong with this code, ive added a new tag name 'light' and i cant get it to respond when i put it on the object, ive used this very similar code in the same scene but the tag has changed to ammo, or health....

What exactly does the |= operator do? [duplicate]

c#,unity3d,unityscript
This question already has an answer here: what does |= (single pipe equal) and &=(single ampersand equal) mean in c# (csharp) 3 answers What exactly does this operator |= do? I have this code for Unity in C# bool shoot = Input.GetButtonDown("Fire1"); shoot |= Input.GetButtonDown("Fire2"); ...

Merging two different texture into one in unity3d

c#,unity3d,unityscript
i am trying to merge two textures into one in unity the first texture is from a webcamTexture the second is from a sprite using : gameobject.getComponent<SpriteRenderer>().sprite.texture as Texture2D I'm having problem in writing the function this is what i did so far : public static Texture2D CombineTextures(GameObject obj, Texture2D...

detecting mouseClick/touch on gameObject

c#,events,input,unity3d,unityscript
the system never detect my mouse/touch Click on a gameObject (the right or left arrow , check the below link) public void OnMouseDown() { //don`t enter here!! if (this.name == "gameObjectName") doAction(); } ...

How to change the shooting accuracy?

unity3d,unityscript
I am making an FPS game using unity 3d, I've a problem in the shooting accuracy script. Can you tell me how I can change it with a single script that shoot the bullet and include the shooting accuracy and equipped to the gun, please?

How to use variables from UnityScript in Boo?

unity3d,unityscript,boo
I've been trying to implement this but without any success. While I was googling around I saw that this is somehow possible but I can't reach it by myself obviously. This my file tree: |-Game |--Assets |---Animacije |---Skripte |----*BlokSistem.js |---Standard Assets |----*UI.boo |---Prefabs |---Sprites |---Game.unity I want to use variable...

Color submeshes in unity3d

unity3d,unityscript
I have a main_mesh that has 10 submeshes, I wonder how I can change the color of of these submeshes to a different color (e.g submesh1 will have a red color, submesh2 will have a blue color,...etc). Any advise please? UPDATE: This is how I'm getting my mesh which has...

checking if Gameobject passing between two other Gameobject

unity3d,unityscript,unity3d-2dtools
I have a three Gameobject(striker)in unity lets say Red,Green and Blue. when i apply gravity force to Green object i want to check if it is passed between Red and Blue or not? and i apply force to Red object i want to check also if it is passed between...

Create one loading scene for many levels in Unity3d

c#,unity3d,unityscript
I have a problem with loading scene. I've create a loading scene, and then when the it's finished, it loads another level, that's the concept, right? Now, the problem is that if I have so many scenes to load, do I have to create so many loadings scenes, too? I...

move an object in a direction using a directional vector

unity3d,unityscript
Ok si i have a game that has object floating in the air. I want to simulate the wind by pushing the floating objects in the same direction of the wind. I have been looking on the internet but i have found no information on how to move an object...

When building to mobile the size of fonts reduce and became very small

c#,user-interface,unity3d,uibutton,unityscript
Like I said in the title when i built to mobile the letter became too small. I think it is because phone has more pixel for his little screen. Well I tried to fix text by simply making text to images in photoshop. But how can I make InputFields text...

Display and render only a specific object in wireframe in Unity3D

unity3d,unityscript
I want to know how to view and render a specific game object (mesh) in wireframe, not the whole scene. I can change the scene to wireframe using GL.wireframe but the problem I want to view and render only a certain object (not the whole scene) in wireframe. Any advice...

How can i stop unity from script?

unity3d,unityscript
I need to close unity from my scripts. As if I clicked on the stop-button in GUI. Can i do this directly from code, or not? I know, how i can close a scene, but need to close all processes.

Unity - In game TV set

unity3d,unityscript
I have some TV model, like and C# code using UnityEngine; using System.Collections; public class ClicktoPlayWebMovieClass : MonoBehaviour { // Use this for initialization void Start () { } private Vector3 FindBoundCord (int i, GameObject _GameObject){ /*This is basically where the code starts. It starts out by creating a *...

OnBecameInvisible not functioning as required

unity3d,unityscript
I am running into strange problem with Unity3d's OnBecameInvisible(). As expected this function should be triggered on the Game objects mesh renderer when it leaves the camera bounds but it gets called when i exit the play mode. ...

Unity 2d instantiating on mouse location trouble, Please advise

java,javascript,2d,unityscript
Ok i have looked all over the web for a solution to this, I may just be blind but if someone could help me out that would be great. The script I am writing is supposed to place a prefab where the mouse has clicked. this is supposed to happen...

photon chat unity plugin - how to know if a friend is online or not

unity3d,unityscript,photon
I am using photon chat plugin in a unity3d multiplayer game. I have added some friends and can send them private message. I want to show if that friend is online or not. I can use on status update callback, but it will show only friends who changed status. How...

Random movement attempt

random,unity3d,artificial-intelligence,unityscript
I'm trying to make my bear walk randomly when the player is not in it's range. I wanted it to randomly select the its rotation in y axis and then move it forward and after some time switch the rotation randomly again. The thing is that I don't really know...

An instance of type '' is required to access non static member ' '

unity3d,unityscript
So i understand this problem, im suppose to make my var static. I get it, but i did it and still have the same problem. Obviously im overlooking something.... Inventory.js private static var emptySlots:int; public static function get EmptySlots():int{ return emptySlots; } public static function set EmptySlots(value:int){ emptySlots = value;...

Unable to delete clones made with instantiation function

unity3d,unityscript
I have made a game where I spawn in several circles which shrink over time until they are supposed to vanish. The problem is, I make all of the circles with the instantiation function. This creates "Ball(clone)" and whenever I try to use Destroy(GameObject) to get rid of one of...

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

loops,unity3d,scripting,while-loop,unityscript
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...

Unity - How to get data from a js script to a csharp script?

c#,facebook,unity3d,sdk,unityscript
I have my player score located in the gameobject _GM (script = gamemaster.js) like this: static var currentScore : int = 0; Now I want this score to be used here: (In the script gameOver.cs located in an other scene) public void SetScore() { var scoreData = new Dictionary<string,string> ();...

Collision trigger always seems to be colliding

c#,unity3d,unityscript
All I can find through research is objects NOT colliding... My problem is it is ALWAYS colliding... I have messed this code up all over trying to make it recognize that it is not colliding. They are not touching anything at all in unity ( cube triggers using box colliders...

Player script not working in UnityScript

unityscript
I put together these code by my self and I get stupid messages like 'found "Time", expected ")".' #pragma strict var RotationSpeed : float = 1.0; //Player rotation speed. var MovementSpeed : float = 5; //Player movement speed; function Update () { transform.Rotate(Vector3(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0) Time.deltaTime RotationSpeed); transform.position(Vector3(Input.GetAxis("Horizontal"),...

Unity 2D controller coding issues

unityscript
I am kind of new to Unity and I am trying to make a game using various tutorials for character controlling but recently I ran into a tutorial where they used this code: using UnityEngine; using System.Collections; public class controller : MonoBehaviour { public float maxspeed = 10f; bool facingRight...

Delete animation of a certain bone for a number of frames Unity3d

unity3d,unityscript
I have an animation of a Mecanim. I wonder how I can delete the animation of only the right-hand for the next couple of frames once I press a certain key in the LateUpdate() function void LateUpdate () { if (Input.GetKeyDown (KeyCode.D)) { //delete the next lets say 100 frames...

BCE0051: Operator '*' cannot be used with a left hand side of type 'int' and a right hand side of type 'boolean'

javascript,c#,unity3d,unityscript
I am follow a unity tutorial. I got an error in my unity car game tutorial BCE0051: Operator '*' cannot be used with a left hand side of type 'int' and a right hand side of type 'boolean'. I found these last two same errors in thease line of code...

Show the name of hit gameObject

unity3d,unityscript,raycasting
I'm creating a project for my school and it was going pretty good until now. I've searched for an answer for nearly an hour and still couldn't find anything (wrong tags?). The thing is that I want to show the name of the item that player is hitting with raycast....

Smooth camera rotation unity

unity3d,camera,rotation,unityscript
I create third person with camera. The camera will move in sync with the mouse move. I create script for camera move, its work but when the speed is high then everything starts to shake. How force the camera move smooth? Vector3 rotation = new Vector3(); rotation = this.transform.rotation.eulerAngles; float...

Modify a captured image in unity3d

unity3d,unityscript
I have a plane which contain a WebCamTexture and a button to capture the image script to capture the image void CaptureAndSave () { Debug.Log (Camera_panel_script.webCameraTexture); Texture2D snap = new Texture2D(Camera_panel_script.webCameraTexture.width, Camera_panel_script.webCameraTexture.height); snap.SetPixels(Camera_panel_script.webCameraTexture.GetPixels()); snap.Apply(); Debug.Log (Application.persistentDataPath.ToString()); System.IO.File.WriteAllBytes( Application.persistentDataPath+"/my_image.png", snap.EncodeToPNG() ); }...

dynamically change a part of the variable path

variables,unity3d,unityscript
I know this question has been asked a bunch of times, but none of the answers (or at least what i took away from them) was a help to my particiular problem. I want to dynamically change a part of the variable path, so i don't have to repeat...

delay on the shot every 3 seconds in unity using c#

c#,unity3d,unityscript
sorry guys I'm new to c# and unity... what I want there is to execute spawner.SendMessage("shoot"); every 3 seconds.. it'll only execute once the condition is met. void Update(){ //first we draw a line from our enemy to our player Debug.DrawLine (player.position, myTransform.position, Color.red); playerDistance = Vector3.Distance(player.position, myTransform.position); if (playerDistance...

Variable value still zero after assigned a value

unity3d,unityscript
I'm making a simple game using Unity where the player needs to pick up coins as much as possible. When the player hits the coin, the coin will disappear and the score will be incremented, for example by 1, here's my script #pragma strict var coinEffect : Transform; var coinValue...

“Identifier Expected” error?

c#,unity3d,compiler-errors,unityscript,identifier
using UnityEngine; using System.Collections; public class Sword : MonoBehaviour { var totalhealth = 100; function OnTriggerEnter(other : Collider){ if(other.tag == "angelic_sword_02"){ totalhealth -= 50; } } function Update(){ if(totalhealth <= 0){ Destroy(gameObject); } } } I get an "Identifier Expected" in the script where it says in the line function...

Hide Cursor script doesn't work correctly in Unity 5

function,unity3d,cursor,unityscript
I've a simple hide cursor script attached in the "FirstPersonCharacter" GameObject and doesn't work correctly. #pragma strict var blocked = false; function Start () { blockCursor (false); } function blockCursor (blocked) { this.blocked = blocked; Screen.lockCursor = blocked; Cursor.visible = !blocked; } function Update () { if (Input.GetKeyDown("e")) { blockCursor(!blocked);...

Unity 5 2d random black lines

c#,unity3d,unityscript
I am having some trouble with rendering sprites in Unity, now before anything I have searched around on google and all the answers haven't worked for me, so here is my problem. I have a tilesheet which has sprites at the size of 16 by 16, the settings for this...

converting string to vector in Unity

vector,unity3d,unityscript
I am trying to convert an array of strings in unityscript with values holding values like: "Vector3(5, 3, 8)" into an array of vectors, but Unity will not take these strings as is. Anyone have any ideas?...

Unity game on iOS ArgumentOutOfRangeException in dictionary

c#,unity3d,unityscript
I have an achievement module for saving and loading a dictionary with the name of the achievement (key) and if it's been accomplished (bool value). I'm using GDE (Game Data Editor) plugin (this one). My module works fine in the Unity editor, saving and loading everything. But in iOS it...

Assigning script to a variable with a variable (Unity 3D)

unity3d,unityscript
So the title is a bit weird but i didnt know how to call it. I am working on a FPS game and I am trying to make a simple weaponsystem. Every Player can have a primary and a secondary weapon. I am at the moment trying to write a...

Hiding a UI panel from script in unity

unity3d,unityscript
I have a UI Panel containing a button as a child ,the button have a script as a component the script is like follow : public GameObject Panel ; OnMouseDown() { Panel.setActive(false); StartCoroutine(takeShot()); } private IEnumerator takeShot() { Application.CaptureScreenshot("my_img.png"); } I am having a problem saying the courotin can't start...