- Home /
Change gameobject tag when player collides with another gameobject
Info: The Small square in the left is the player, constantly moving forward. The horizontal platform under the player is tagged "New".
Question: When the player collides with the vertical wall in front of him, the tag of the horizontal platform below should change its tag, from "New" to "Old". How do i do that using a c# script?
Huge thanks to anyone who takes the time to read this and tries help out.
Answer by CodeVector · Jun 21, 2020 at 12:14 PM
Add a Rigidbody to your Player, and check "Is Kinematic" box. This should fix your problem. Otherwise, check in your tag list if "New" and "Old" tags are created.
sorry i didnt specify, im asking for the c# code to do this, im not sure how to program the code that makes the tags of specific objects change.
using UnityEngine;
public class YourScript : $$anonymous$$onoBehaviour {
public GameObject platformBelow;
void OnCollisionEnter(Collision collision) {
if(collision.transform.CompareTag("$$anonymous$$yWall")) {
platformBelow.tag = "Old";
}
}
}
1) Create a new tag "$$anonymous$$yWall", and use it for you vertical wall. 2) Add this script to your player. 3) Reference the "Platform Below" in the inspector.
Your answer
Follow this Question
Related Questions
Collision on specific Frames 1 Answer
Specific GameObject Collision Issue 1 Answer
Distribute terrain in zones 3 Answers
How to stop object from going through walls. 4 Answers
Collisions and Lists 1 Answer