Destroy a gameobject after your preferred amount of seconds in Unity script (C#)

Multiple ways to do this but the way I did it was:

1. Created and attached the script to the object I wanted to destroy
2. In the script created a public gameObject
3. In the start put the destroy instructions = “Destroy(objectIWantedToDestroy,numberOfSeconds);”
4. In the editor dragged the object into the newly created public gameObject spot.

Example:

public gameObject objectIWantToDestroy;

{//Beginning of example class

start()
{//beginning of start function

Destroy(objectIWantToDestroy,4); //will be destroyed in 4 seconds
}//end of start function

}//End of example class

Link where I found the answer:https://answers.unity.com/questions/400517/shoot-script-question.html

Unity 5 Graphics – Lighting Overview – Unity Official Tutorials

~Directional lights start before 2:00
~Ambient light starts at 2:00
~How to create procedural skyboxes starts at about 3:50
~Baked lights start at 4:30
~Light bounce settings including off shaders around 7:00
~Indirect light at 7:20
~Emissive surfaces at 7:27 – found emission on materials could not find it on shaders but that doesn’t mean it does not exist
~Probes start at 8:30
~10:13 is when the switch from linear to gamma colored space for mobile games

Notes:
+Realtime is heavier than baked lighting
+Baked lights are easier on platforms with lower capabilities like mobile devices

Smooth Rotation Script

//********************************************************************//
//Company:Ayoku Animation
//Game Name:Space Schooner
//Script Name: goldRotation
//Script Purpose: Rotate the gold coins on one axis
//********************************************************************//

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class goldRotation : MonoBehaviour
{//Beginning of goldRotation Class

#region Settings
public float rotationSpeed = 99.0f;
public bool reverse = false;
#endregion

void Update()
{//beginning of update function

rotate();

}//end of update function

public void rotate()
{//beginning of rotate function

//if (this.reverse)
//transform.Rotate(Vector3.back * Time.deltaTime * this.rotationSpeed);
// transform.Rotate(new Vector3(0f, 0f, 1f) * Time.deltaTime * this.rotationSpeed);
//else
//transform.Rotate(Vector3.forward * Time.deltaTime * this.rotationSpeed);
transform.Rotate(new Vector3(0f, 0f, 1f) * Time.deltaTime * this.rotationSpeed);

}//end of rotate function

public void SetRotationSpeed(float speed)
{//beginning of SetRotationSpeed function

this.rotationSpeed = speed;

}//end of SetRotationSpeed function

public void SetReverse(bool reverse)
{//beginning of SetReverse function

this.reverse = reverse;

}//end of SetReverse function

}//End of goldRotation Class

How to create regions in unity scripts for cleanliness and organization

#region

//code here

#endregion

then you can collapse or open the code like functions.

you can also name the region so you can easily distinguish them each other for example:

#region public variables

public Text healthText;

#endregion

  • and thus when collapsed only the region’s title “public variables” will be visible

 

Unity Turret Tutorial – Part 2b Shooting System by Chris Gough = Straight Projectile and Tracking Projectile Work, beam does not

~~~~~~~~~~~~~Beginning of Fyis~~~~~~~~~~~~~
by 14:12 they solve the for(int i =0; projectileSpawns.Count; i++) error line
with for(int i =0; i < projectileSpawns.Count; i++)

13:22 they solve error for float angle = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(transform.rotation – target.transform.rotation));

with

float angle = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(transform.position – target.transform.position));

~17:12 when i noticed my line render was off~

~~~~~~~~~~~~~End of Fyis~~~~~~~~~~~~~

Code for the different ways to find gameobjects in unity

https://docs.unity3d.com/ScriptReference/GameObject.Find.html

*Read intro first
Finds a GameObject by name and returns it.

This function only returns active GameObjects. If no GameObject with name can be found, null is returned. If name contains a ‘/’ character, it traverses the hierarchy like a path name.

*Importante!!!! = For performance reasons, it is recommended to not use this function every frame. Instead, cache the result in a member variable at startup. or use GameObject.FindWithTag.

Note: If you wish to find a child GameObject, it is often easier to use Transform.Find.

Note: If the game is running with multiple scenes then Find will search in all of them.

using UnityEngine;
using System.Collections;

// This returns the GameObject named Hand in one of the Scenes.

public class ExampleClass : MonoBehaviour
{
public GameObject hand;

void Example()
{
// This returns the GameObject named Hand.
hand = GameObject.Find(“Hand”);

// This returns the GameObject named Hand.
// Hand must not have a parent in the Hierarchy view.
hand = GameObject.Find(“/Hand”);

// This returns the GameObject named Hand,
// which is a child of Arm > Monster.
// Monster must not have a parent in the Hierarchy view.
hand = GameObject.Find(“/Monster/Arm/Hand”);

// This returns the GameObject named Hand,
// which is a child of Arm > Monster.
hand = GameObject.Find(“Monster/Arm/Hand”);
}
}
GameObject.Find is useful for automatically connecting references to other objects at load time; for example, inside MonoBehaviour.Awake or MonoBehaviour.Start.

For performance reasons, it is recommended to not use this function every frame.

A common pattern is to assign a GameObject to a variable inside MonoBehaviour.Start, and use the variable in MonoBehaviour.Update.

using UnityEngine;
using System.Collections;

// Find the GameObject named Hand and rotate it every frame

public class ExampleClass : MonoBehaviour
{
private GameObject hand;

void Start()
{
hand = GameObject.Find(“/Monster/Arm/Hand”);
}

void Update()
{
hand.transform.Rotate(0, 100 * Time.deltaTime, 0);
}
}