unity5

a field initializer cannot reference the nonstatic field method or property 'Component.GetComponent<Rigidbody>()'

久未见 提交于 2019-12-11 07:56:38
问题 I have no idea what is going on, I am trying to follow a tutorial that was written in Unity 4 and a lot has changed. This is as far as I have gotten and now I am stuck. public class PlayerMovement : MonoBehaviour { public float moveSpeed; public static Rigidbody rb = GetComponent<Rigidbody>(); private Vector3 input; // Use this for initialization void Start() { } // Update is called once per frame void Update() { input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

Check key press when OnTriggerStay() is called

前提是你 提交于 2019-12-11 07:24:55
问题 I have an NPC that my player can talk to when the players collider is colliding with the NPC, I do that using this piece of code: private void OnTriggerStay2D(Collider2D other) { if (other.gameObject.tag == "InteractiveArea") { if (Input.GetKeyDown(KeyCode.E)) { Debug.Log("PRESSED NPC"); CreateAndShowDialog(); } } } However, this gets called really randomly, sometimes the first time I press "E", sometimes the second or third time, etc. My rigidbodies: The colliders I use are standard

How do I move the Rigidbody in FixedUpdate, but still have my character be affected by gravity?

大兔子大兔子 提交于 2019-12-11 07:22:33
问题 So Below you see what I initially used to control my characters movement. _RigidBody.velocity = _ConstantWalkingSpeed * direction.normalized; This works for walking around in 4 directions. However, if my character falls over an edge, he falls veeeeeery slowly. If I then in mid air disable the walking script, gravity picks up and goes at normal speed. This leads me to believe that my movement script somehow affects the gravity effect. As such I tried this solution: _RigidBody.velocity =

Change UI RectTransform position after setParent()

一个人想着一个人 提交于 2019-12-11 06:35:09
问题 I have these lines : GameObject bp = Instantiate(MyPrefab); bp.transform.SetParent(GameObject.FindGameObjectWithTag("ContentFactory").transform); bp.transform.localPosition = new Vector3(0, 0, 0); Si, I just instantiate a prefab, I set a parent and I want to change the position. My problem is, the function SetParent set a fixed position to my bp GameObject, and after that I don't know how to change this position. The last line change nothing.... The same with .position . How can I change the

How do I save/load the state of every gameObject in a sandbox game?

☆樱花仙子☆ 提交于 2019-12-11 06:32:13
问题 I am struggeling to grasp how to handle save/load of every GameObject in a Scene. I currently save data in a Json and it works fine, the part I'm struggeling with is the logic of saving an entire game state. For example, I'm making a sandbox game where you can shop trees, hoe ground, plant crops, pick herbs, etc, etc. All of these interactable GameObjects are created from prefabs and that works fine. But I need to somehow save every GameObject and its state (i.e is a crop fully grown or not,

PNG file displayed as red question mark after download with HttpWebRequest

本小妞迷上赌 提交于 2019-12-11 02:46:11
问题 I face the following issue: I downloading a png file from google drive, all bytes are successfully received (as it seems), but when I try to construct a Texture2D and set it as Sprite in an Image , only red a question mark appears. Am I missing something? Code below: HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://content.googleapis.com/drive/v3/files/" + fileId + "?alt=media"); request.Method = "GET"; request.ContentType = "image/png"; request.Headers.Add("Authorization"

How to save score in Unity

谁说胖子不能爱 提交于 2019-12-11 01:09:42
问题 I am stuck with the following problem: I have a fishing game. So far, if I play the game, I can start fishing, catch 2,3,4 more fish and everything is fine. However, if I want to pause the game (Pressing ESC or a button that I placed in the scene) my score resets. Additionally, I don't know how to save my score, even if I pause the game or go into shop button. Start function void Start() { PlayerPrefs.GetInt("Pesti"); NrPesti.text = PlayerPrefs.GetInt("Pesti").ToString(); PlayerPrefs.GetInt(

Unity High_Score Badges C#

二次信任 提交于 2019-12-10 22:20:33
问题 Hello I want to create badges like in flappy bird , I put images in UI images like GameObjects. But it show me only one image of 3 images Please Please Help Out! And HighScore works , it rewrites when I get Higher score , but don't know why images won't change :( Sorry For bad english using UnityEngine; using UnityEngine.UI; using System.Collections; public class ScoreManager : MonoBehaviour { private float score = 0f; public Text Scoretext; public MenuController deathmenu; public GameObject

Daydream Non-VR Mode in Unity 5.4.2f-GVR13 [duplicate]

柔情痞子 提交于 2019-12-10 22:15:21
问题 This question already has an answer here : Enable/Disable VR from code (1 answer) Closed 2 years ago . last week I tried to integrate my Unity project to Daydream, the integration went fine. Now I am trying to seperate the first scenes (which include login process so I need the android soft-keyboard) from the rest of the application - I want the application to open like any android-non-vr application and to switch to VR mode only after the first two scenes. I read in some answer by Unity

Unity Error: UnityEngine.Component' does not contain a definition for `velocity'

♀尐吖头ヾ 提交于 2019-12-10 22:03:30
问题 I am very new to C#, so forgive me if this is obvious. I am following the steps in this tutorial and have run into a problem on step six. The error it gives is this: The error it gives is this: UnityEngine.Component' does not contain a definition for `velocity' and no extension method `velocity' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?' Here is the code: using UnityEngine; using System.Collections; public class RobotController : MonoBehaviour { /