Tag Info

New answers tagged

0

Occlusion query.... http://blogs.msdn.com/b/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx It is described well enough there.


0

you might try having the on enter adding the enemy to a 'target list', and on exit/killing enemy have that entry removed from the list. using System.Collections.Generic; // lets use use the magical 'List' array List<GameObject> targetedEnemies; // List arrays let us add and remove stuff later, // that is, they do not have a maximum capacity and won't ...


1

Perhaps this is what you are looking for: transform.forward = transform.up;


0

If you don't care about the interior being painted in, there's a really simple solution. First, draw all circles in black. Next, draw all the circles again in white, with a smaller radius - basically subtract a border width from the radius. The result will be a constant thickness black border around a white area. You could maybe even use this black / white ...


0

At the end of your update step you have lastInput = currentInput;, which will happen even if the character is jumping. So in essence when you get into the FixedUpdate step your lastInput variable will always be the same as the currentInput variable. By the looks of it, Vector2 currentInput = new Vector2( Input.GetAxis("Horizontal"), ...


0

Ok, as I said in my comment above, I have come to believe my problem is a genuine bug in Unity 4.x. I haven't tried Unity 5.0 yet, might be fixed there, but I couldn't wait anymore and I just hacked a non-polymorphic solution. I'm going to not green-check this answer in case some hero out there magically comes up with the right solution, but for the ...


0

Don't use character controller, instead of it use rigidbody+capsuleCollider and then control rotation and forces with script as Wardy stated. Here is a video that may be helpful: Video


1

You probably could draw, and save 'intersection points' any point where two circles draw a point at same location. Then use that set, knowing that inside and outside changes when an intersection occurs. You would then only need to check any one point between two intersections to know the status of an entire arc between any two intersections. Fewer checks ...


0

Depending on exactly what you are trying to achieve, I might recommend not scaling anything (either the camera or your sprites) and instead just worry about the differing aspect ratios (eg. moving things to the edges of wider screens). Things will scale to fill the screen automatically; the graphics won't be pixel-perfect anymore, but with the ...


1

Looks like the options are ... Implement your own version of the rigidbody script. Make your world a whole lot bigger and rotate it under the player as they move rather than rotating the player round the world.


1

I can see why you would want to do that, if the random number was a key seed to a sequence, having the same number twice would create the same sequence. You could create a table to use as your randoms at program start time, then check it for duplicates, and replace with another random till every number is unique. If you add all the numbers to a map while ...


2

That sounds really odd to me. This might sound like a good idea if you've got some bad/biased RNG. Another possible use case would be some game with random loot where you'd like to guarantee your player to get some special drop once every x tries rather than having a very bad streak. However, for your own use case this doesn't sound very useful at all, ...


0

Turns out I need to call the method by name with a string instead of the method itself to stop the coroutine. StartCoroutine("AttackEnemy"); ... StopCoroutine("AttackEnemy");


2

Or how is this, draw each circle on some memory, then after all are drawn, set the inside of every circle to zeros, clearing any intersection lines. clarification On some memory is meant to indicate separate texture Set to 0 is meant to indicate set to transparent. setting inside transparent on second draw sequence is fill with transparent color with ...


-1

Or draw your circles as filled, then trace the edge that would work also. tracing edges method would only be computationally a better method with a very large number of circles. Where edge trace is faster then second set of drawing.


0

If any point is closer to the center of any circle then the radius of that circle clip it. Although you would probably want to find the intersection points where any two distances equal to the radius of a circle, from any two different circle centers are equal, to get clean edges where intersection occurs. basically any point inside another circle is ...


1

maybe you don't get the reference to the right animator, to TEST (or DEBUG) define it public public Animator anim; , run the game and watch in the inspector if it has referenced the right one. If the animator you need is attached to the same object where you attached the script it should work, but if they are not attached to the same game object it doesn't. ...


2

I found out that the Content.mcgb is actually a little GUI helper and you can generate and easily load a .spritefont file with it. Steps: 1.Load the GUI app by double clicking the "Content.mcgb" file in the "Content" folder 2.Go to Edit -> New Item... -> Choose SpriteFont and give it a name -> Hit "Ok" 3.Go to Build -> Build (or hit F6) - You should get ...


0

You've already got most of the setup. What you could do is just control the Campfire from the other collider inside the Collision method [untested code] : // in CollectableItems.cs //... if (other.gameObject.tag == "CampFire") { if (count > 0) { var campfire = ...


1

The GameObject car is not set to anything. That means it's null. This is exactly what the error message is telling you. Just because you happen to have a prefab named 'car' in your Assets folder doesn't mean you can name a variable car and expect Unity to know you're talking about the same thing. See my answer to your other question to learn one way to ...


1

If you put the prefab into a directory called Resources inside your Assets directory, you'll be able to use the Resources class and its load functionality. This will load a prefab up as a GameObject, which can then be instantiated. For example: GameObject myRoadInstance = Instantiate(Resources.Load("road")) as GameObject; Will create a instance of your ...


0

Vector3 position = new Vector3(5, 5, 5); GameObject newGameObject = Instantiate(GameObjectToInstantiate); newGameObject.transform.position = position; You will always need to know what your going to instantiate, but from there you just call Instantiate as a function and load it into a new gameObject. You have to position it separately.


2

As pctroll said, the right solution for you is to use virtual functions. To answer the question "how does Unity do that" without virtuals (i.e.: you don't have to override Awake or Update in MonoBehavior derived classes) they use Reflection to call theese functions by their names (string).


4

We just have to declare Awake, Update, and any other function created by us, to be public and virtual on the parent. Override the function on the children. public class AgentBehaviour : MonoBehaviour { public virtual void Awake() { // your code here } public virtual Vector3 GetVector3 () { return new Vector3(); } } ...


2

When a unit/structure/weapon attacks, I would probably create an Attack (subclassed with all your fun details) that takes the attacker and the defender (or defenders). The Attack can then interact with the target/defender (slow, poison, damage, change state), draw itself (beam, ray, bullet), and dispose of itself when it's done. I can foresee some issues ...


4

Generally, you want to avoid excessive hierarchy. What if a player wants to attack an object (such as a trap, or door?) How would a trap attack a player? What about environmental hazards? I would suggest an entity-component system over inheritance here. Give everything that has health a Health component, and give everything that can attack a Weapon ...


2

As this rapid google search states: gameObject.tag="new_tag"; Obviously your "new_tag" has to exist inside the editor.


3

You seem to have rectangles that are sandwiched: You have rectangles A, B and C A directly above and is overlapping B, which is above and overlapping C. The update for A is done, pushes it a bit up. The update for B is done, pushes it a bit up because of C, and a bit down because of A. B hasStopped because it did not move because your [x|y]Shift is ...


4

I don't know a whole lot about Unity and I haven't done game development in a while, so let me give you general programming answer to this question. I have based my answer on the knowledge I have about entity-component systems in general , where an entity is a number that is associated with N many components, a component only contains data, and a system ...


8

Well, I'm honestly not an expert on this but... I think it depends on how complex and varied you think the attacks will become. Since it's an RTS I'm guessing you'll have maybe 10-50 or so different units or structures with their own attack types. Option 1: If there is a relatively low number of units that will have attacks that are somewhat similar I ...


1

Well.. sometimes you have to formulate a question and stop work until you find your answer yourself. In the evening I had some thoughts about resource management. We're talking about .Net ... thus a GC is involved. What if the finalizer thread comes along at a wrong time or state. Well - that would be actually a double fault. Not more right therefore, ...


2

One simple way of doing it could be to make a few alternate versions of the script and have different AI profiles for the enemies (just give them a random one when created). This way you could have one type that goes straight ahead like you have now, but also others that try to get the player by curving right or left. Maybe even one that makes some random ...


1

Simply draw your sprite before the call to GraphicsDevice.SetRenderTarget(null);


0

Dragging the prefab file over gives it a reference to the prefab, not the actual instantiated version you've got in your scene. If you drag the text box over from the scene itself, you should have no problem. You will see something like "GUIText" appear in Score Text instead of "None".


0

First of all, you should stop incrementing inventory, if you don't spawn more projectiles. Example: if (Input.GetTouch(i).phase == TouchPhase.Began){ if(inventory < 3){ // spawn 3 at max OnShoot (); inventory++; } } Then decrease inventory whenever a projectile gets destroyed. Eg. void OnTriggerEnter2D(Collider2D other) { ...


0

Your bouncing is caused by calculus imprecision, mixed with the time integration component. This kind of things happen with involvement of these components: contacts detection response impulses integration Point 1 we don't know who does it in your code. I guess some framework feature, the result of the contact information is given to you in the ...


1

So what you're doing is a pseudo-3D game then. The world works in 3D coordinates, but you just display stuff in 2D. To do things like these, you probably want to keep the character coordinates in 3D, and use these to calculate the sprite coordinates in 2D. It's totally up to you how you want your game to be controlled, but if for example, you use the X ...


0

This is what works for me in 3D using flattened cubes for a "floor". I make a cube prefab and attach this script: using UnityEngine; using System.Collections; public class move : MonoBehaviour { public int strength; private GameObject[] gO; // Use this for initialization void Start () { } // Update is called once per frame void Update ...


3

Camera.main will be null if you don't have a camera in your scene with the tag MainCamera. If you don't want to tag the camera, you can't use Camera.main but you can specify the Camera script you want to use. Something like: GameObject cameraObject = GameObject.Find("MyCamera"); Camera myCamera = cameraObject.GetComponent<Camera>(); Vector2 ...


1

In each Rock GameObject, just have a script that fires off a StartCoroutine in the Mono Start() method. The method the Coroutine calls can either have a yield WaitForSeconds call or your own custom timer logic before firing off the increase in speed. In regards to adjusting the speed of each object, I'm assuming you have something like a RockController ...


0

as Instantiate creates a duplicate of a prefab, just attach a script defining your Rock to the rock GameObject and make sure you have in the Start() function a constructor that takes the elapsed time and modify your rock speed consequently.


0

You should collect the 3 capsule objects like GameObject[] capsules = GameObject.FindObjectsWithTag("capsule"); (perhaps you should add a tag to your gameobjects) and then your line will be meshPoints.text = "Points: " + (capsules[0].GetComponent<ScriptAttached>().points_right + capsules[1].GetComponent<ScriptAttached>().points_middle + ...


0

I just leave it here. click1, click2 (see UISystem and UIComponent) It's free and it works. If you have questions please ask me in comment or chat.


1

List<Vector3> newList = new List<Vector3>(originalList); newList.Insert(0, currentLocation); originalList in this example hasn't been modified and should have 1 less element than newList. Another way: List<Vector3> newList = new List<Vector3>(); newList.Add(currentLocation); newList.AddRange(originalList);


0

It may be elseswhere but as far as we can see from the code you've provided there doesn't seem to be a call to PlayerPrefs.Save(); and without it the value won't be persisted. EDIT: Per comment from @Lohoris this isn't the case as it saves automatically on Application.Quit. As @Byte56 points out the issue may still be related if the application is being ...


1

The camera will normally render with an aspect ratio equal to Screen.width / Screen.height but this can be overruled. This script will have an effect similar to taking 16:9 image from the camera then stretching it to fill the screen. This will of course cause some distortion. using UnityEngine; public class CameraAspect : MonoBehaviour { public float ...


8

You're assigning the value of money to the print return value, not the actual int value being returned. money=print(PlayerPrefs.GetInt("Money")); Should be money=PlayerPrefs.GetInt("Money");


1

If you're creating a new gameObject using something along the lines of CreatePrimitive then you could following that with some logic to change it's scale programatically {Warning: untested code} : public class SceneController : MonoBehaviour { private GameObject cube; private float cubeScale = 1.0f; void Awake() { } void Start() { } ...


0

My understanding from reading your code is that you send a message passing a param (the damage amount) ... gameObject.SendMessage("OnDamage", damage); You then declare a method that takes no params to handle it ... void OnDamage(){ My guess is that the unity compilation process is not creating a correlation between these 2 because of that mismatch.


0

some reference : https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html Check Both objects (bullet and enemy) have a collider with 'Is Trigger' enabled plus the bullet has a rigidbody. You can use the collider you prefer. I rewarote youre code this way: // Update is called once per frame void Update () { transform.Translate ...



Top 50 recent answers are included