Collision.transform
Declaration
public Transform transform;Описание
Transform объекта, на который мы попали (только для чтения).
Если мы столкнулись с коллайдером с Rigidbody, то преобразованием будет преобразование, прикрепленное к жесткому телу. Если мы столкнулись с коллайдером без жесткого тела, то преобразованием будет преобразование, прикрепленное к коллайдеру.
// Attach this script to a GameObject with a Collider and Rigidbody. // Make sure the object you’re colliding with also has a Collider (and optionally a Rigidbody).
using UnityEngine;
public class CollisionLogger : MonoBehaviour { private void OnCollisionEnter(Collision collision) { // Get the transform of the object we collided with Transform hitTransform = collision.transform;
// Log the position, rotation, and scale of the hit object Debug.Log("Collided with: " + hitTransform.name); Debug.Log("Position: " + hitTransform.position); Debug.Log("Rotation: " + hitTransform.rotation); Debug.Log("Scale: " + hitTransform.localScale); } }