unityscript

trying to keep a game object within the screen left and right bounds in unity3d

隐身守侯 提交于 2020-01-16 02:39:05
问题 I have this code bellow for my gameobject : private float screenx; Vector3 playerPosScreen; void Start () { screenx=Camera.main.pixelWidth-renderer.bounds.size.x ; } void update(){ playerPosScreen = Camera.main.WorldToScreenPoint(transform.position); if (playerPosScreen.x >= screenx) { //playerPosScreen.x=screenx; transform.position=new Vector3 (screenx, transform.position.y,transform.position.z); } //txt.text = playerPosScreen.x.ToString(); else if(playerPosScreen.x<=renderer.bounds.size.x){

Textures loads in editor but not in standalone (appears pink)

别说谁变了你拦得住时间么 提交于 2020-01-14 03:04:28
问题 I'm using an asset named Simple Obj , that allows me to import an obj, their materials and the textures associate . This works fine in my editor but not in my standalone. My OBJ are not in my resources file , I take it from another file with the WWW method. Here's how I do it, t his download my OBJ, create a Gameobject and place it in my scene : private IEnumerator DownloadAndImportAllInBackground(string url, Plane newPlane) { string objString = null; string mtlString = null; Hashtable

Multithreaded Script invocation in Unity3d

我与影子孤独终老i 提交于 2020-01-13 13:12:58
问题 I was trying to implement multithreaded script execution in Unity3d, but it seems that the there is no way provided by Unity libraries and we have to use System.Threading provided by Mono. But they have mentioned that Unity Scripting is not thread safe. Can i implement Multithreading safely and efficiently in Unity3D using System.threading or other Platform independent API ? Also how can i make sure that the scripts are running in parallel ? An example or a link would be highly appreciated.

Multithreaded Script invocation in Unity3d

拜拜、爱过 提交于 2020-01-13 13:11:16
问题 I was trying to implement multithreaded script execution in Unity3d, but it seems that the there is no way provided by Unity libraries and we have to use System.Threading provided by Mono. But they have mentioned that Unity Scripting is not thread safe. Can i implement Multithreading safely and efficiently in Unity3D using System.threading or other Platform independent API ? Also how can i make sure that the scripts are running in parallel ? An example or a link would be highly appreciated.

Accessing variable from other script

点点圈 提交于 2020-01-10 05:35:06
问题 How do I call a variable from other script components? mirror.transform.position = cop.GetComponent("AI_Car").mirrorPos; It seems that the public variable carPos declared in the script AI-Car-script cannot be accessed: 'mirrorPos' is not a member of 'UnityEngine.Component'. 回答1: 2 things: 1) I work in C#, so I may be wrong about this, but I think you have to get the component and THEN get the variable. For example: var otherScript: OtherScript = GetComponent("AI_CAR"); var newPosition =

Unity LookAt 2d Equivalent

三世轮回 提交于 2020-01-02 09:29:09
问题 I'm creating a tank fighting 2D game top-down in Unity 3D in the 2D perspective active. My axises are X and Y (defaulted) and I'm trying to create a homing missile My missile code is code is: var enemyName :String; // which enemy does this shot seeks private var target :GameObject; var speed :float = 100; private var timeToTarget:float; function Start () { timeToTarget = Mathf.Abs(speed); if (timeToTarget<=0) { timeToTarget=150; } target = GameObject.Find(enemyName); Destroy(this.gameObject,

Why does Resources.Load <Sprite> return null?

不羁岁月 提交于 2019-12-31 12:55:28
问题 My project has multiple sprites located in Assets\Sprites which I want to load using C# script. I have tested this: Sprite myFruit = Resources.Load <Sprite> ("Graphics_3"); But myFruit is still null. 回答1: Resources.Load will search for a directory in Assets/Resources . If you want to put it to Sprites directory then put it inside Resources (ex. Assets/Resources/Sprites ). Then you can just load it like this: Sprite myFruit = Resources.Load <Sprite> ("Sprites/Graphics_3"); Also make sure that

Unity 3D - Limit Camera Rotation

孤街浪徒 提交于 2019-12-31 05:29:07
问题 I have found several awnsers to this question online, and I have tried all of them, but they either break my camera, or just overall don't work. Here is my script: using UnityEngine; using System.Collections; public class fp : MonoBehaviour { public float speedH = 2.0f; public float speedV = 2.0f; private float yaw = 0.0f; private float pitch = 0.0f; void Update() { yaw += speedH * Input.GetAxis("Mouse X"); pitch -= speedV * Input.GetAxis("Mouse Y"); transform.eulerAngles = new Vector3(pitch,

Unity - Gameobject look at mouse

牧云@^-^@ 提交于 2019-12-31 01:19:32
问题 I've ran into a problem. The basic setup I have right now, two objects: my camera, and my player object. The player moves via Transform on WASD, and is supposed to rotate on mouse movement. The camera is top down (At a slight "3ps" style angle, which keeps the player object centre to the camera's perspective, and rotates according to the players rotation. This is the players movement script: http://pastebin.com/SvN8FuWs This is the players rotation script: http://pastebin.com/uzZ7SKFL The

Dragging Item With Icon Following Pointer Unity C# [duplicate]

依然范特西╮ 提交于 2019-12-25 17:55:11
问题 This question already has answers here : Unity3D UI, calculation for position dragging an item? (3 answers) Closed 3 years ago . How To Dragging Item With Icon Following Pointer ? MAYBE IT WILL TAKE SOME TIMES TO SEE ALL THE CODE. Many thanks Before for your attention. But I have done a little Code Before. And it is run successful, but there is some mistake in my code. Actually the icon dragging is following the pointer but it just temporary. And my prediction is because i make an paging