Codes
Answers
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");
}
}
}
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;
}
}
}
}
}
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;
}
}
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);
}
}
using UnityEngine;
using System.Threading.Tasks;
public class Play_audio : MonoBehaviour
{
async void Start()
{
await Task.Delay(1000)
Your_fncton();
}
}
/* 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);
using UnityEngine;
public class lerp_demo : MonoBehaviour
{
Quaternion rot=new Quaternion(0.4f,0.5f,0.9f,1);
void Start()
{
transform.rotation=rot;
}
}
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);
}
}
using UnityEngine;
public class Rotation_demo : MonoBehaviour
{
Vector3 rot=new Vector3(10,10,10);
void Start()
{
transform.Rotate(rot);
}
}
Questions
Answers
Answer accepted
Users
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us