unity transform code example
Example 1: unity how to make jump script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class jump : MonoBehaviour
{
public float jumpHeight = 7f;
public bool isGrounded;
public float NumberJumps = 0f;
public float MaxJumps = 2;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (NumberJumps > MaxJumps - 1)
{
isGrounded = false;
}
if (isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(Vector3.up * jumpHeight);
NumberJumps += 1;
}
}
}
void OnCollisionEnter(Collision other)
{
isGrounded = true;
NumberJumps = 0;
}
void OnCollisionExit(Collision other)
{
}
}
Example 2: how to get the transform of an object in unity
Transform YourGameObjectsTransfrom = YourGameObject.transform;
Example 3: c# transform
using UnityEngine;public class Example : MonoBehaviour
{
void Start()
{
foreach (Transform child in transform)
{
child.position += Vector3.up * 10.0f;
}
}
}
Example 4: how to set a transform equal to something unity
public Transform tr;
tr.position = new Vector2(x, y);
Example 5: how to reference a transform unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExampleScript : MonoBehaviour
{
private Transform player;
private void Start()
{
player = GameObject.Find("Player").transform;
}
}