Using OnCollisionEnter with 3 objects
I'm trying to make a little game ish in my class but i just began programming a few weeks ago. So i want to do so when i hit an object, with my player it moves a different object. So when Players (1) hit my stribe, i want Death1 to move (ignore death2). but i don't know how to put in that i want it to move death1, so it only moves my stribe right now.
using System.Collections; using System.Collections.Generic; using UnityEngine;
[SerializeField] GameObject Death1; [SerializeField] GameObject Death2;
private void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Players (1)")
{
Vector3 playerPosition = transform.position;
playerPosition.x = 1.7f;
transform.position = playerPosition;
}
void Start () { Death1 = GetComponent(); Death2 = GetComponent(); }
Answer by tormentoarmagedoom · Aug 31, 2018 at 12:16 PM
Good day.
I'm not sure to understand what you need. As I understood, only need to change the position of the Object2.
You need to find that object inthe scene or assign it via inpecor, and just change vaue of
Object2.transform.position
You should look some basic tutorials about referencing.
Bye!
Your answer
Follow this Question
Related Questions
I'm using a Trigger for a projectile and I'm having trouble getting everything to work properly 0 Answers
Scripting Errors 1 Answer
My coroutine script isn't working, it has no errors 0 Answers
How do I make this script play a particle sytem from prefab 1 Answer
How to make an Object follow this Path,How to make an Object follow an Path 0 Answers