Unity 5 collider is not working - graphics

I have 2 prefabs (a character and a wall), I attached a capsule to the player and a cube to the wall. Both capsule and player, have the collider component. The problem is that my character walks through the wall. I need your help, please!

Collider defined without RigidBody component is called Static Collider in Unity. If you do so, Unity assumes that the object will never move in the scene.
On the other hand, if your object is an active one (moving), you need to attach RigidBody component in addition to Collider component.
In your case, you need to attach a rigidbody to your character.
For more info: http://docs.unity3d.com/Manual/CollidersOverview.html

Add a RigidBody component to them.

Related

Unity2D: Add text to rigidbody2D element

I'm new to Unity and I started with the Catch Game Tutorial to learn to create a 2D game. Everything is working now but for my needs, I would like to add different textboxes to each of the fallen elements (in the tutorial the bowling balls) Those texts should move with the objects. I know I can change text dynamically in the code, but I couldn't figure out how to correctly add the element.
I tried to add a text object as a child of the gameobject and also tried to create a new gameobject which contains a text, but I can't position the element in front of the background and above my wished element (I can't choose a sorting layer for this)
Imagine this is the object which has to be collected and I would like to show a text like this:
My Questions are:
1. How can I add a text to be displayed in the correct position (GUIText, text in a gameobject, only text or something else?
2. How can I make this text dynamically move with the fallen object?
3. Can I set a background to my text as displayed above?
Thank you in advance!
I found a solution for my problem and did the following thing:
I created a Sprite with my wished background (black rectangle) and added it to the scene
I created a 3D Text and added it as a child to the created Sprite (and scaled it and positioned it)
I added a Script to the 3d Text with the following content:
void Start () {
this.gameObject.GetComponent<Renderer>().sortingLayerName = "[MyLayerName]";
this.gameObject.GetComponent<Renderer>().sortingOrder = 3;
}
I added the Sprite (with the text as child) to my gameObject (ananas)
A renewed the object in the Prefabs folder
Maybe my solution helps other people facing a similar problem.

Move view from top to bottom continuously without animation in Android

I want to know how to move a view from top to bottom continuously without animation. I am asking this because I want to get the position of the view at every step so that I can check that if there is any collision between that view and any other view.
With animation you can move (not exactly move) a view from one position to another position (Animator class), but animation produces an illusion to the user that it is moving but it's position is fixed all the time. So this can't be done using animation?
Second approach is incrementing position of view. I applied this method in onCreate(). If I used it without Thread.sleep(50) then the activity doesn't show the view, if I applied it with Thread.sleep(50) then activity doesn't start for some period.
Property animation (subclasses of Animator class) actually move the view, as they update the actual property of the view. It is the view animations (subclasses of Animation class) that don't move the actual view and instead just where it appears to the user.
Source:http://developer.android.com/guide/topics/graphics/prop-animation.html
Quote: With the property animation system, these constraints are completely removed, and you can animate any property of any object (Views and non-Views) and the object itself is actually modified.
You also shouldn't start moving things around in the onCreate method as things are still initializing (onwindowfocuschanged is recommened). Also if you call thread.sleep, you are going the sleep the main UI thread, hence freezing the application for a time.
Solved the problem using ValueAnimator :-
CodeSnippet :-
va=ValueAnimator.ofFloat(0.0f,size.y);
va.setDuration(5000);
va.setRepeatCount(va.INFINITE);
va.setRepeatMode(va.REVERSE);
va.start();
va.addUpdateListener(new AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
// TODO Auto-generated method stub
bullet[0].setTranslationY((Float) va.getAnimatedValue());
Rect R11=new Rect(bullet[0].getLeft(),bullet[0].getTop()+(int)bullet[0].getTranslationY(),bullet[0].getRight(),bullet[0].getBottom()+(int)bullet[0].getTranslationY());
Rect R21=new Rect(ball.getLeft(), ball.getTop(), ball.getRight(), ball.getBottom());
if(R11.intersect(R21))
va.cancel();
}
});

Is there a built-in element for a bullet slider in android?

Is there a ready-made view element in Android for (I don't know if this is the right name but) bullet sliders?
I mean this:
Ideally a class that handles the activation of the bullet at the given the position would be perfect.
You're looking for a ViewPageIndicator. Check out the sample app.

Sprite class in OpenFL (formerly NME) for empty placeholder objects?

I am experimenting with Haxe and OpenFL and am wondering if the Sprite class is synonymous with a GameObject in Unity. It seems that sprite instances have a hierarchical structure and I am wondering if this can be utilised to manage objects.
For example:
Game (Sprite / container / no visual representation)
|--> Grid (Sprite / container / no visual representation)
|--> Tile (Sprite)
|--> Tile (Sprite)
|--> ...
|--> ...
Am I correct with the above assumption, or should the Sprite class be extended purely for objects with visual representation?
If you only need a container, you should extend DisplayObjectContainer. But for abstract things like Game, I wouldn't use a DisplayObject at all, but custom classes.
Use classes extending from DisplayObject only for things that should be added to the Display List. In your example, Game shouldn't be a Sprite, but Tile and Grid probably yes.
Well, I use that in my project, so probably the answer is 'yes' :)
In particular I use a grid with N horizontal sprites, so my isometric map is rendered in proper top-to-bottom order. I also use a single container for my HUD etc.
There are some caveats to this approach - "invisible" sprites cannot capture mouse events, and they cannot have their width/height set programmatically (only by adding children at appropriate positions).

java ME creating your own layer

Is it possible to create your own Layer?
like:
public class MyLayer extends javax.microedition.lcdui.game.Layer{
(...)
}
i get the error: "Layer() is not public in Layer; cannot be accessed from outside the package."
I wanted to draw some 2D graphics (import javax.microedition.lcdui.Graphics), and on top of that a Sprite coursor. Graphics are mostly still, so there's no need to draw them every time, so i thought layerManager will help me, but with that one i'd need it to be a Sprite or a TiledLayer. Creating my own Layer would solve the problem.
Layer is not designed for extension outside the javax.microedition.lcdui.game package. The error messages is clear about it.
But you may extend TiledLayer or Sprite.
Update
As paint method on both classes is final (pointed by #bartholomew-surma on comments) my above statement is invalid.
Another approach is to create a mutable Image, call getGraphics method, draw the 2D graphics in it and finally paint the sprite.

Resources