unityscript

Bullet not moving unity

六眼飞鱼酱① 提交于 2019-12-11 16:45:03
问题 At the moment I have a script that is firing a sphere, when i press the button which makes it fire; the pellet comes out but does not move across the screen, it just stays in a stationary position. whereas I would like it to move across the screen forward... Script: #pragma strict public var pellet : Transform; function Start () { } function Update () { if (Input.GetKeyUp("o")) { var pelletfire = Instantiate (pellet, gameObject.Find("pellet_Spawn").transform.position, Quaternion.identity);

Application.platform == RuntimePlatform.Android not working

岁酱吖の 提交于 2019-12-11 15:58:24
问题 Like I said in this other question that no one has answered: Touch not working on Unity on my Android device I discovered that the problem of my app not working was this lines: if (Application.platform == RuntimePlatform.Android) { } If i remove that condition the app works like it should but the moment i add it back it just doensn't work. 回答1: Follow you posts, I did an experiment. First, I try run below code on Remote 5 and run it as an individual app respectively. void Update () { Debug

Unity 2D: Area Hue Shift Effect

£可爱£侵袭症+ 提交于 2019-12-11 15:37:38
问题 I am trying to create a transparent GameObejct in Unity that if active, changes the color hue of anything behind it by 180 degrees. The effect can be easily seen in Photoshop if my explanation is not good enough. I can guess I will need a shader for this, but my shader making knowledge is quite limited as of now, so any help would be appreciated. Thank you! Example made in photoshop of the desired effect: 回答1: You can take the shader from this post and make the following adjustments: 1) Add a

Search a substring in an array of Strings in unityscript

江枫思渺然 提交于 2019-12-11 15:06:42
问题 I'm trying to search a substring in an array of Strings. I'm using the following code (in Unity3): var obstacles = ["Border", "Boundary", "BoundaryFlame"]; var frontAvailable = true; var leftAvailable = true; var rightAvailable = true; var hitFront: RaycastHit; if (Physics.Raycast(transform.position, transform.position + transform.forward, hitFront, 1.5)) { Debug.Log("I hit this in front: "); Debug.Log(hitFront.collider.gameObject.name); for (var i = 0; i < obstacles.length; i++) { if

How to load scripts, materials on GameObject in runtime in Unity3d?

£可爱£侵袭症+ 提交于 2019-12-11 14:52:01
问题 I'm new to Unity3d and in JS scripting and I need help to symplify a scene and code in the app I'm developing Here is the concept of my scene: There is a Camera, that sees through layer masking, three planes. Also there is a material that acts as a swapping texture, and a script that runs this swapping respectively on each plane. In order to run this script, I use a GUI with a scroll list buttons, so when button1 is pressed, camera sees only plane1 and the script1 runs the texture material1

Finding size of images imported at runtime

天大地大妈咪最大 提交于 2019-12-11 13:26:31
问题 I am currently loading images at runtime from directories stored in an XML file, and assigning them to RawImage components via the WWW class. While this is working fine, the image is skewed to fit into the new texture size. I am wondering how to get an image’s original size or aspect ratio so that I can change the size of the image rect to suit. The images to be imported are at varying sizes and therefore the approach used needs to be responsive to the original size of imported images. Any

Rotate a gameobject in Unity

对着背影说爱祢 提交于 2019-12-11 13:05:29
问题 Trying to write a script for Unity that takes the position and rotation of game object A and assigns it to game object B using C#. The debug log shows the correct rotation angle that I'm wanting to get, but I don't know how to actually assign that value to the other game object. I'm brand new to C# as of today, so it could very well be my syntax, but I'm also fairly new to Unity. Thanks in advance! using UnityEngine; using System.Collections; public class MoveArrow : MonoBehaviour { void

Unity download a video from server and save it

亡梦爱人 提交于 2019-12-11 04:38:20
问题 I want to fetch a video from my server and save it in my assests to view it later in my game. I am aware of use of www. but i dont understand how to download the video from my server giving it's url. below is the code to get video as a texture. var www = new WWW("http://Sameer.com/SampleVideo_360x240_2mb.mp4"); var movieTexture = www.movie; Any idea how do I save the mp4 file ? 回答1: Using UnityWebRequest API. You can use UnityWebRequest public class VideoDownloader: MonoBehaviour { void Start

how to destroy an item after collision

我的未来我决定 提交于 2019-12-11 04:18:13
问题 I am creating an fps game, I have created the gun, the bullet, and the enemy. Now I want to make my enemy destroyed after the collision with bullet. My enemy is a gameobject named Fire and tagged Enemy and my bullet named "Cube 1(Clone)" and tagged "Cube 1(Clone)". I made a script for that: #pragma strict function OnTriggerEnter(theCollision : Collider) { if(theCollision.gameObject.name=="Cube 1") { Destroy(gameObject); Debug.Log("Dead"); } } But it does not work. 回答1: You need to check the

How to destroy a game object marked “DontDestroyOnLoad” when a new scene loads?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 03:48:15
问题 So I created a music player to play music through all my menu and story scenes without interrupting, but then in my game scene I want to delete that music. How can destroy the playing music when my game scene loads? Here is my music script: #pragma strict var offsetY : float = 40; var sizeX : float = 100; var sizeY : float = 40; var musicPrefab : Transform; function Start () { if (!GameObject.FindGameObjectWithTag("MM")) { var mManager = Instantiate (musicPrefab, transform.position,