Codes
Answers
using UnityEngine;
public class for_raycasting : MonoBehaviour
{
void FixedUpdate()
{
int layerMask = 1 << 6;
layerMask = ~layerMask;
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 System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timerexample : MonoBehaviour
{
float val;
bool srt,stp,rst;
public Text disvar;
void Start()
{
val=0;
srt=false;
stp=false;
rst=false;
}
void Update()
{
if(srt)
{
val += Time.deltaTime;
}
double b = System.Math.Round (val, 2);
disvar.text = b.ToString ();
}
public void stopbutton()
{
srt=false;
}
public void resetbutton()
{
srt=false;
val=0;
}
public void startbutton()
{
start=true;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timerexample : MonoBehaviour
{
float cntdnw = 30.0f;
public Text disvar;
void Update()
{
if(cntdnw>0)
{
cntdnw -= Time.deltaTime;
}
double b = System.Math.Round (cntdnw, 2);
disvar.text = b.ToString ();
if(cntdnw < 0)
{
Debug.Log ("Completed");
}
}
}
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.Collections;
public class Camera_Follow : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
private Vector3 newtrans;
void Start ()
{
offset.x = transform.position.x - player.transform.position.x;
offset.z = transform.position.z - player.transform.position.z;
newtrans=transform.position;
//not taking y as we won't update y position.
}
void LateUpdate ()
{
newtrans.x= player.transform.position.x + offset.x;
newtrans.z= player.transform.position.z + offset.z;
transform.position = newtrans;
}
}
using UnityEngine;
public class Unity_lerp : MonoBehaviour
{
float start_value=80f;
float end_value=50f;
// Update is called once per frame
void Update()
{
Camera.main.fieldOfView=Mathf.Lerp(start_value,end_value,Time.time/5);
}
}
using UnityEngine;
public class Unity_lerp : MonoBehaviour
{
Quaternion start_pos;
Quaternion end_pos;
float timer=0;
// Start is called before the first frame update
void Start()
{
start_pos=transform.rotation;
end_pos=Quaternion.Euler(90, 0, 90);
}
// Update is called once per frame
void Update()
{
transform.rotation=Quaternion.Lerp(start_pos,end_pos,timer/5);
timer+=Time.deltaTime;
}
}
using UnityEngine;
public class Unity_lerp : MonoBehaviour
{
Vector3 start_pos;
Vector3 end_pos;
Vector3 ofset= new Vector3(5,0,0);
float timer=0;
// Start is called before the first frame update
void Start()
{
start_pos=transform.position;
end_pos=transform.position+ofset;
}
// Update is called once per frame
void Update()
{
transform.position=Vector3.Lerp(start_pos,end_pos,timer/5);
timer+=Time.deltaTime;
}
}
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