avatar
Vionix
0

Codes

8

Answers

Code compilers

Top answers

0
unity raycast
April-12-2022
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");
        }
    }
}
0
unity stopwatch
April-12-2022
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;
}
}
0
unity countdown timer
April-12-2022
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");     
  } 
}
}
0
unity instantiate
April-12-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
Camera follow player unity
April-12-2022
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;
}

}
0
mathf.lerp unity
April-12-2022
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);
        
    }
}
0
lerp rotation unity
April-12-2022
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;
        
    }
}
0
unity lerp
April-12-2022
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;
        
    }
}