New answers tagged

2

It might be useful to note that while it is not guaranteed to be unique, your original approach is still going to work in practice with small amounts of traits, and a collision would not even have disastrous consequences if it happened. The chance that some combination of hashes will match the hash some other trait is n!/2^32 (for a 32-bit hash), which is ...


1

The "true" parameter that you have set is meant for allowSceneObjects, so you will be able to drag a scene object into that field, however I am unsure if passing your own type will always work. From what I've seen it is only able to use type that Unity recognize, Transform, GameObject, TextAsset (which could be .txt, .cs, .ja), etc. Also, your object in ...


1

Yes, setting a global variable and then calling a method which behaves differently based on its value is a dangerous anti-pattern known as "Accumulate and Fire". The remedy is to pass all data which is required by a method as parameters. In your case the solution is to not use generic event handlers to enter a state. Give each state an unique Enter method ...


1

A fine way to handle in a discrete way communications between entities is the Oberver pattern. Take a look at it. each entity who need observation will need to add an observer to its list public void AddObserver(Observer o) { obs_l.Add(o); } Then when you define your Notify function you will baasically pass a reference to the object calling, if it is ...


4

As Phillipp said, HashCodes do not guarantee uniqueness. In fact they pretty much don't guarantee anything. What you seem to want to do is to generate a unique number from a unique string. How to do that generically is answered in this question: How can I generate a GUID for a string? If you just want a unique identifier which is allowed to differ even for ...


21

Hash codes are never guaranteed to be unique. Also, you do not get a guarantee that adding hash-codes gets you an unique value which does not collide with a different combination of hash-codes. The usual solution to identify a combination of on/off flags is to use a bitfield. Assign manual integer values to your enum which are all powers of two: [Flags] ...


0

I'm assuming guess variable will have a text from InputField, if so you could use this line to split the string from checking to NewLine string[] guessWords = guess.Split('\n'); and then retrieving the specific word from the guessWords array like if (string.Equals(guessWords[0], code)) { Debug.Log("code 1 correct"); } else { Debug.Log("code 1 ...


0

This is caused by the order in which unity normally renders objects. Transparent objects are the glitchy exception to this order, as unity tries to calculate draw only one transparent object per pixel for what it thinks are opaque objects. There are a few approaches to this issue. You could use the Pass solution with Zwrite On and ColorMask 0, but in your ...


0

Apparently all that was going wrong was happening when I declared the Input structure here: struct Input { float2 uv_MainTex; float4 color; }; All that was going wrong was going wrong due to the fact that I forgot to explicitly specify the COLOR semantic on this line: float4 color; With the COLOR semantic specified, the above line of code ...


-1

GameObject bulletInstance = Instantiate(bullet, transform.position, player.transform.rotation) as GameObject; bulletInstance.GetComponent ().velocity = transform.right * bulletSpeed;


0

Why are you changing the position of the camera using transform.position += newTargetOffset - targetOffset; ? While panning, you should only rotate the camera. Also, what is targetOffset?


0

The box collider on the parent object is marked as "is Trigger". Maybe your code for the collision detection for this collider is causing the player to die when colliding with the parent object.


0

You should generate mipmaps, those are textures for objects further away, antialiasing could also help to make things smooth


0

In order to play an animation there needs to be an Animation Component attached to your GameObject. In that animation component you can add the animations you wish to play. If you don't want the animation to play on start make sure you un-check "Play Automatically". If you want to add more animations click the "Animations" drop down and set the "Size" to the ...


0

You could add a trigger to the plane and then write a script to check, if an object with a tag "Player" is inside it (don't forget to set the players tag to "Player") . Make the speed variable in the player movement script to public so that other scripts can access it. Then when the player is in trigger set the speed variable higher, and when ever the player ...


0

You need to set up states in the animator panel. You can open it by double clicking on a animation controller. To create a animation controller just drag the animation Clip onto the gameObject you want. Once you have the animator panel opened you need to create a parameter to handle the transitions. Here is a picture of a example Animator set up. Then you ...


2

For anyone looking for good network simulation software go here https://jagt.github.io/clumsy/ Clumsy doesnt need installed or anything, just run it and specify your parameters. I realise it is really simple but it is what I needed. Hopefully this helps.


1

Just to mention: Since I posted this question, I went on the official website to register as an "official" developer. I could get their approval in less than a month. I think the commercial situation of the WiiU is so bad that they are ready to let anyone try to make great games. But I still need to buy or rent dev material which is a bit expensive for ...


0

Following Draco18s comment, I'm using a 3D object which is moved around the screen by tracking the live video object. Then I apply a depth mask to this object which behaves as if there was an actual object there since it allows my background to be seen wherever this object would be usually seen while still remaining invisible.


0

you can use System.Serializable using UnityEngine; using System.Collections; public class grouping: MonoBehaviour { [System.Serializable] public class class1{ public enum myEnum {one,two,three}; public myEnum[] row; public string name; public int price; } public class1[] array; }


1

If you want to just have one GameObject for your character, you cannot add multiple Colliders of the same type to your GameObject and still have the ability to access all of them in your scripts (only the first in order of components would be accessible). However, you CAN add multiple Colliders of DIFFERENT types while still maintaining accessibility. In ...


0

Another option would be to use animation curves. You can learn more about them here, as I am not entirely familiar with them.


0

The onTriggerEnter has a typo and it will be OnTriggerEnter. The OnTriggerEnter is invoked whenever there will be a collision between a trigger and a rigidbody. Thus the Collider object will be referenced by the trigger and hence the defined action would be performed as of the function definition by the OP.


5

Having a value deplete over time can be done a few different ways. The simplest is likely using the update method to deplete at a constant rate. public float myValue = 10; //the total public float subractPerSecond = 1; //remove this every second public void Update() { //subtract at a constant rate and ensure it stays at or above 0 myValue -= ...


2

You can do something like this. It looks monumentally stupid (Unity has an awesome editor, why not use it?), but just in case you do have a good reason: You can't create scenes programmatically, but you can have an empty scene and add whatever you need programmatically. Using prefabs is probably not the best idea: prefabs are usually loaded only when ...


0

Are you calling FixedUpdate() or defining it? I think you should delete the opening brace after FixedUpdate(), and add a ; directly after FixedUpdate(). In other words, if your intent is to call the method, you should write FixedUpdate (); If your intent is to define a new method called FixedUpdate (), you should write void FixedUpdate(){ //code// ...


-1

You just change [PUN] to [PunRPC].


2

What you are looking for is a HingeJoint. Note that when you want it to start swinging, you need to give it a little push in form of a small impulse (like with AddForce on Start, for example).


0

I don't know if this idea will work for you, but could you use a single animation and randomly offset starting point of it for each handle? They won't sync up because they are all randomly offset. Of course, if you want them to swing to the train movement, this may not look so good.


0

Maybe I know whats is happening :), as you can read in the unity documentation: http://docs.unity3d.com/Manual/ExternalVersionControlSystemSupport.html When you use version control Unity has problems to manage the Library folder and you have to delete it manually. So the process is the following Close Unity Make a pull of the repository Go to the folder ...


0

You have several options: Create a variable public GameObject TreeGroup in your DisableTrees behavior. The variable will now appear as a field in the inspector of DisableTrees. You can then drag the TreeGroup game object to it. Use GameObject.Find to find the tree group by its name. But keep in mind that this method is very slow on larger scene graphs. Add ...


2

Based on your description, I would make each card effect verb a class & then use composition to combine them into cards as needed. E.G. the draw cards action would be an effect class, its parameters might be # of cards, source drawn from & type of draw. Damage player might be another effect class & its parameters might be amount & ...


2

It isn't possible to prevent that, however you can get a call when the parent transform changes and set it back to the correct value. Transform m_DesiredParent; void Awake() { m_DesiredParent = transform.parent; } void OnTransformParentChanged() { if(transform.parent != m_DesiredParent) { transform.SetParent(m_DesiredParent); ...


0

It could be Constructive Solid Geometry indeed. But they said in the store page it is a voxel-based world (unless they lied of course). Which is basically pixels in 3D (or i could say cubes in the case of minecraft, and others). In this case, it seems to me they smooth out those voxels to achieve that organic looks. Something like Castle Story which you can ...


3

It is very possible(with a quick refactoring), and you dont need to know the actual type, worry about deriving or need to instantiate every gameObejct manually in code. A simple trick with extension methods will do: just "add" a field and extension method to the GameObject class: public static class GameObjectExtensions { private static readonly ...


0

You want to move 2d UI (Label) with respect to your game object. WorldToScreenPoint transform the position from world space into screen space. Here you are on right track, what you are missing is that screenPosition = Camera.main.WorldToScreenPoint(transform.position); screenPosition.y = Screen.height - screenPosition.y; So, according to me your script ...


-3

You can use my AudioManager. To do so, put my Custom Unity Library into your project. Then you can play multiple audio the way you want: AudioManager.Instance.PlayAudio(myAudioClip); You can stop audio, specify 3D audio positions, etc. I hope this helps. Let me know if you have any questions.


0

I've been working on a similar project based in Zero-G in which I need all game objects to generate and react to both gravitational and electromagnetic force based on their volume, density, mass, energy and conductivity. I'm relatively new to scripting, but I've made a few modifications to the script above to make it work for me in a 3D space (as far as ...


2

No, not really, as the method is not virtual. The closest reasonable approach is to derive from GameObject and implement a new SetParent method: public new void SetParent (Transform transform) { throw new NotSupportedException("I'm afraid I can't do that."); } However, this will only fail at runtime and even then only if you call SetParent through an ...


1

Converting between a Quaternion (transform.rotation) and an Euler angle triplet is not possible the way you wrote it. See the API http://docs.unity3d.com/ScriptReference/Transform-rotation.html for the meaning of the transform.rotation property. If you want to double check or verify that your Euler angles are correct, you can convert them to a quaternion ...


0

I wiped up a script that does what you want I think. Check it out. public class OrientTowardsDirection : MonoBehaviour { Vector3 prevLoc = Vector3.zero; Vector3 moveDirection = Vector3.zero; public Transform cube; private float MaxTurnSpeed = 100; void Start() { //code for simply moving the camera was here but was removed as per ...


0

https://developer.android.com/guide/topics/manifest/supports-screens-element.html we have to add the Screen support in Manifest file..


1

That's correct. In a few cases, you will want to take into account the rigidbody.inertiaTensorRotation. It defines the rotation of the moment of inertia. However, in most cases, this is just going to be the identity quaternion.


2

inertiaTensor is a Vector3, inertiaTensorRotation is a Quaternion. And from the docs for inertiaTensor: The inertia tensor is rotated by the inertiaTensorRotation. Essentially, inertiaTensor is the moment of inertia (defined as a tensor) and the inertiaTensorRotation is how that tensor is rotated. If you'd like them to be calculated automatically, you ...


0

Ok how do I explain this. I have a singleton that acts as a data holder. While developing the scene with the game manager I had attached the singleton to the gamemanger object that hold a bunch of scripts. Now when I made the main menu I ofc added my singleton to it so I can carry info to the game scene and because of this my whole game manger object was ...


0

Stumbled upon this looking for something else. SteamVR_Controller.Device has a method GetAxis() (as you have already tried using) and the default parameter is the touchpad so you don't want to pass any value. That will return the Vector2 position on the touchpad that you are touching. controller.GetAxis() should be all you need. The returned Vector2 goes ...


1

My guess: At the bottom of MoveShip() you are setting the velocity to zero, if the player is at the boundary. As your code in Rotate() depends on the x and y components of the velocity (which is set to zero in the previous update, when at the boundary), the rotation will be set to Quaternion.Euler(0,0,0) in these occasions One way to solve this could be to ...


0

I think I may have solved my issue. I managed write my own code: public class Anti_Roll_Bars : MonoBehaviour { private float force; private Vector3 pos; public float roll_bar; public WheelCollider wheel; public Rigidbody car_rb; public Transform car_tf; // Use this for initialization void Start () { car_rb = GetComponent<Rigidbody> (); } // ...


1

I'm not currently at my computer to show a valid demonstration, however, I've used "Camera.main.ScreenPointToRay(Input.mousePosition)" casting that ray and referencing the point that it hits. You could set that point to be the position that your character looks at via Vector3.lookToward(). Also,you are correct, this would work regardless of camera angle as ...


0

I Finaly find my Solution. When I do Debug.Log(hit.transform.name), I can see that only hit in my Aim, so Physics.Raycast() works in the wrong way, I just change my Layer Type to Ignore Raycast, as it is in the picture: When I changed the Layer Type, I could see that my Script was right, and works. So I can select a object tag (in my case a ...



Top 50 recent answers are included