my player is in position -2 ,-4 . enemy has speed of -4 in X axis and when collides with player , just moves it in x axis towards left , but i need after colliding both game objects become without movement , i mean still and fix in collision point .how is it possible? Here is my class :
using UnityEngine;
using System.Collections;
public class PlayerAnimationController : MonoBehaviour {
private Animator anim;
void Awake()
{
anim = GetComponent<Animator> ();
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Enemy")
{
Debug.Log ("Player");
var running = false;
anim.SetBool ("Running", running);
}
}
}
Grab the Rigidbody2D via GetComponent() from each colliding object and set its X velocity to 0?
thanks . another question please :
when i load a scene with SceneManager.LoadScene(2); or go to next scene and come back to the current scene , its always this exception error and cannot find my objectpool prefab instances , how i can fix this problem ?
here is my object pool class
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ObjectPool : MonoBehaviour {
public RecycleGameObject prefab;
private List<RecycleGameObject> poolInstances = new List<RecycleGameObject>();
private RecycleGameObject CreateInstance(Vector3 pos){
var clone = GameObject.Instantiate (prefab);
clone.transform.position = pos;
clone.transform.parent = transform;
poolInstances.Add (clone);
return clone;
}
public RecycleGameObject NextObject(Vector3 pos){
RecycleGameObject instance = null;
foreach (var go in poolInstances) {
if(go.gameObject.activeSelf != true){
instance = go;
instance.transform.position = pos;
}
}
if(instance == null)
instance = CreateInstance (pos);
instance.Restart ();
return instance;
}
}