gameobject

GameObject's Following a Leader / Centipede Issue

情到浓时终转凉″ 提交于 2019-12-12 14:33:59
问题 I am having difficulty chaining together some GameObjects to "Follow the leader". This is what I am trying to accomplish: Where there is a "head" object and it pulls the body objects with it. Like a snake or centipede. However, this is what is happening: They all kinda follow the head and but they seem to move as a whole. Can anyone see what I am doing wrong? Here is my Centipede Object that the others classes inherit from. I started to tinker with the idea of just making the CentipedeObject

Put a text onto a game-object BUT as if it was painted

会有一股神秘感。 提交于 2019-12-12 07:38:55
问题 I was looking for this answer on the web for some time. But apparently my search phrases were wrong or it is really that hard. But I doubt it. Imagine, I have any 3d-body. A sphere, cylinder or cube. I want to put a text onto that object. As if it was a sticker or painted onto that object. Meaning, it would follow the objects curves or edges, if wrapping around them. I managed to create some texts which are ALWAYS in front or behind my object. But that is not what I want. The closest to what

How to instantiate object class that contains GameObject?

徘徊边缘 提交于 2019-12-12 04:45:25
问题 I am attempting to instantiate a large number of "particles" using a C# script in Unity. I have created a particle class that contains the creation of a corresponding GameObject. The GameObject within each particle instance is a sphere. When attempting to instantiate a new particle (Particle p = new Particle(...)) I get a Unity warning that the 'new' keyword should not be used. "You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be

C# - Drag and then Drop in specified area

眉间皱痕 提交于 2019-12-12 04:30:12
问题 I want my Item / GameObject, that to have its limit of draging. GameObject that have a place to stop, and wont able to use again. Droping Target/ Specified Place to Drop. First Place of Bed The bed that have moved. In here, but the bed overlap the chair the should have bump. This is the bed that i want to end. The bed that can only move from its first place upto the side of the chair. Im still wondering if it is in some kind of "Vector" code. Im newbie so im still exploring, and also, since

Accesing a script attached to another object

风流意气都作罢 提交于 2019-12-12 00:52:43
问题 I have a set of code attached to one of my game objects, that I am trying to access from the script in another object. I am trying to access the "Move" function in this script: using UnityEngine; using System.Collections; public class MoveBackwards : MonoBehaviour { #region Inspector public float maxRotationDegrees = 10f; public float rotationSpeed = 2f; public float maxDistance = 5f; public float moveSpeed = 2f; #endregion //Inspector private float traveledDistance; private float

Access dynamically added Component in Unity3d C#

馋奶兔 提交于 2019-12-11 18:32:58
问题 After adding a Component to a GameObject via the GameObject.AddComponent method, how can I access this Component from another script? here is myScript code (not attach to a GameObject): using UnityEngine; using System.Collections; public class MyScript : MonoBehaviour { public string myName = "myName"; public Vector3 pos; public bool visible; } and here is the main code attached to a gameobject in the scene: using UnityEngine; using System.Collections; public class Main : MonoBehaviour {

How to precisely sample data with frequency of 60Hz?

£可爱£侵袭症+ 提交于 2019-12-11 04:13:35
问题 Actually, I use the InvokeRepeating method to invoke another method every 1/x seconds. The problem is that the precision of the delay between the invoke and the data I got is not good. How I can precisely sample transform.position with a frequency of 60Hz. Here's my code: public class Recorder : MonoBehaviour { public float samplingRate = 60f; // sample rate in Hz public string outputFilePath; private StreamWriter _sw; private List<Data> dataList = new List<Data>(); public void OnEnable() {

Is there a way two make two trigger gameObjects collide?

Deadly 提交于 2019-12-11 03:12:07
问题 This is for a 2D game. I have a Player who can shoot trigger projectiles(with a trigger collider) and Enemies that can do the same. When a Player projectile collides with the Enemy, stuff happens and vice versa. However, when the Player projectile and the Enemy projectiles collide, they just ignore collision, go through each other, and nothing happens. They also have a Rigidbody2D with continuous collision detection. Is there a way to make it so something happens when these two gameObjects

What is the difference between GetComponent<Image> ().enabled and .SetActive (false); in unity

隐身守侯 提交于 2019-12-10 23:17:35
问题 I have been trying to use SetActive () to turn on and off GameObjects. I couldn't figure it out and ended up using: GameObject.Find ("ObjectName").GetComponent<Image> ().enabled = false; to turn off an image. I am not trying to use the same script to turn off a GameObject that has multiple animations nested inside it. GameObject.Find ("ObjectName").GetComponent<???> ().enabled = false; GameObject.Find ("ObjectName").SetActive (false); I am not sure what goes in the <> , but I have read I can

Unity3D - get component

时光毁灭记忆、已成空白 提交于 2019-12-10 17:18:49
问题 What is the simplest way to getcomponent in Unity3D C# ? My case: GameObject gamemaster. //C# script MainGameLogic.cs(attached to gamemaster). A boolean backfacedisplayed(in MainGameLogic.cs). A function BackfaceDisplay()(in MainGameLogic.cs). Another C# script FlipMech.cs , which I need to check from MainGameLogic.cs if(backfacedisplayed == TRUE) , I will call BackfaceDisplay() from MainGameLogic.cs . How can I do it in C#? In js is rather straight forward. In FlipMech.js : //declare