transform
The Transform of the object we hit (Read Only).
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Property
- Namespace: UnityEngine
- Assembly: UnityEngine.PhysicsModule
public Transform transform { get; }
Remarks
If we collided against a collider with a Rigidbody, the transform will be the transform attached to the rigidbody. If we collided against a collider without a rigidbody, the transform will be the transform attached to the collider.
Examples
// 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); }}