2D Toolkit Forum
2D Toolkit => Support => Topic started by: tunahantolga on July 27, 2013, 09:35:40 pm
-
0
I am making jumping game and I have a problem.(I am using Unity 4 and 2D Toolkit.) I have a 3 sprite in scene.First layer, second shaman(main character), third gold. I want to collision shaman and gold.When shaman touched gold, I want to destroy gold.
Here is the code:
void OnTriggerEnter(Collider collision) {
Destroy(collision.gameObject);
if (collision.gameObject.tag == "goldshaman") {
Destroy(gameObject);
}
}
I made a shaman tag is goldshaman and shaman and gold is own to sphere collider. Also is trigger marked.(gold and shaman). Shaman and gold is same z axis.Gold is moving and touched shaman but gold is not destroy.
Simply can't work why?
Please help guys.
-
How are you moving your character?
-
Gold has a other C# code. And I changed goldWiggle value and goldSpeed. Example goldWiggle x= 3, y=0, goldSpeed=1.
So gold pass through shaman but gold is not destroy.
Here is the code:
public Vector3 initPas;
public Vector2 goldWiggle;
public float goldSpeed;
// Use this for initialization
void Start () {
initPas = transform.position;
}
// Update is called once per frame
void Update () {
transform.position = initPas + new Vector3(Mathf.PingPong(Time.time * goldSpeed, goldWiggle.x), 0, 0);
}
-
I add a Rigidboy(use gravity and is kinematic) on Gold and Shaman. After solved a problem.