avatar
GonaRip
0

Codes

13

Answers

Code compilers

Top answers

0
Unity raycast script
January-08-2023
using UnityEngine;
public class ForRaycasting : MonoBehaviour
{
    
    void FixedUpdate()
    {
        int layerMask = 1 << 6;//Since Friend is layer number 6
        layerMask = ~layerMask; //Inverted to ignore layer
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 10,layerMask))
        {            
            Destroy(hit.collider.gameObject);
        }
        else
        {            
            Debug.Log("Did not Hit");
        }
    }
}
0
car controller Unity
October-18-2022
using UnityEngine;

public class car_controller : MonoBehaviour
{
    public WheelCollider[] wheel_col;
    public Transform[] wheels;
    float torque=100;
    float angle=45;
    
    void Update()
    {
        for(int i=0;i<wheel_col.Length;i++)
        {
            wheel_col[i].motorTorque=Input.GetAxis("Vertical")*torque;
            if(i==0||i==2)
            {
                wheel_col[i].steerAngle=Input.GetAxis("Horizontal")*angle;
            }
            var pos=transform.position;
            var rot=transform.rotation;
            wheel_col[i].GetWorldPose(out pos,out rot);
            wheels[i].position=pos;
            wheels[i].rotation=rot;
            
        }
        if(Input.anyKeyDown) 
        {
            if(Input.GetKeyDown(KeyCode.Space))
            {
                foreach(var i in wheel_col)
                {
                    i.brakeTorque=2000;
                }
            }
            else{   //reset the brake torque when another key is pressed
                foreach(var i in wheel_col)
                {
                    i.brakeTorque=0;
                }
                
            }
        }
        
       
        
    }
}
0
unity instantiate prefab as child
August-14-2022
using UnityEngine;
using System.Collections;

public class Instantiate_example : MonoBehaviour 
{ 
  public Transform prefab;
  void Start() 
  { 
     Gameobject childprefab=Instantiate(prefab, new Vector3(2.0F, 0, 0), Quaternion.identity) as Gameobject;
     childprefab.transform.parent = GameObject.Find("parent object").transform;
  } 
}
0
unity instantiate prefab
August-14-2022
using UnityEngine;
using System.Collections;

public class Instantiate_example : MonoBehaviour 
{ 
  public Transform prefab;
  void Start() 
  { 
     Instantiate(prefab, new Vector3(2.0F, 0, 0), Quaternion.identity);
  } 
}
0
unity async await
July-07-2022
using UnityEngine;
using System.Threading.Tasks;

public class Play_audio : MonoBehaviour
{

    async void Start()
        {
  
         await Task.Delay(1000)
         Your_fncton();   
            
        }
}
0
unity quaternion
June-30-2022
/* Quaternion is a combination of a vector3 and a scalar used to represent the rotation or orientation of an object.

The structure of quaternion looks like this (xi, yj,zk,w) where (xi,yj,zk) is a unit vector that represents the angle between the orientation and each individual axis. “w” represents the degree of rotation along the unit vector (xi,yj,zk).

In Unity, Quaternion can also be represented using a vector 4. */

Quaternion rot=new Quaternion(0.4f,0.5f,0.9f,1);
0
euler angles to quaternion unity
June-30-2022
 rot.eulerAngles=new Vector3(45,0,90);
0
quaternion rotation unity
June-30-2022
using UnityEngine;

public class lerp_demo : MonoBehaviour
{
    Quaternion rot=new Quaternion(0.4f,0.5f,0.9f,1);
  
    void Start()
    {
       transform.rotation=rot;
        
    }
}
0
Rotating an object in Unity using Physics
June-22-2022
using UnityEngine;

public class rotation_example : MonoBehaviour
{
    public float torque;
    public Rigidbody rig;

    void Start()
    {
        rig = GetComponent<Rigidbody>();
    }

    void FixedUpdate()
    {
        rig.AddTorque(transform.up * torque);
    }
}
0
Rotating an object in Unity
June-22-2022
using UnityEngine;

public class Rotation_demo : MonoBehaviour
{
    Vector3 rot=new Vector3(10,10,10);
  
    void Start()
    {
       transform.Rotate(rot);
        
    }
}