Unity c# change light temperatur with script - c#

im trying to write a script that makes the temperature of the light whatever number is set in the float
i need this for later reference when i add a slider or selectable options that determine the temperature of the light
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class lightchange : MonoBehaviour
{
public float Temp = 2000f;
private void pp()
{
Light lightcomp = GetComponent<Light>();
lightcomp.colorTemperature = Temp;
}
}
this is my code but it doesnt seem to work and this is all i could find online to edit componentswhat im trying to change

Related

Unity C# dialogue system script displays only first letter of public var

I have a pretty strange problem. I was coding a simple dialogue system, for now it will only display a letter every 0.1 seconds.
I have a TextMeshPro text that contains the text to be displayed.
Here is attached my DialogueLine.cs script:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
namespace DialogueSystem
{
public class DialogueLine : DialogueBaseClass
{
private TextMeshProUGUI textHolder;
[Header ("Text Options")]
[SerializeField] private string input;
private void Awake()
{
textHolder = GetComponent<TextMeshProUGUI>();
StartCoroutine(WriteText(input, textHolder));
}
}
}
it gets the value of my "input" variable, setted from Unity interface. The script calls the "WriteText" coroutine, in the DialogueBaseClass.cs script:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class DialogueBaseClass : MonoBehaviour
{
protected IEnumerator WriteText(string input, TextMeshProUGUI textHolder)
{
for (int i= 0; i < input.Length; i++)
{
textHolder.text += input[i];
yield return new WaitForSeconds(0.1f);
}
}
}
A pretty simple script that adds on my "textHeader" component a letter from the input every 0.1 seconds.
But, here is the problem. The output of my component is only the first letter of the input variable: if in the input I write "Hello" it displays "H".
I really can't find the problem in this script...

Why does setting my Rotate.z change all variables?

Im trying to make a sprite rotate onscreen to show the player how their Jet is rotated while they fly.
Here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AircraftScript : MonoBehaviour
{
public float Altitude;
public Text AltitudeText;
public GameObject AircraftImage;
public GameObject Aircraft;
void Update()
{
Altitude = Aircraft.GetComponent<Rigidbody>().position.y;
AltitudeText.text = Altitude + "ft";
AircraftImage.Rotate.z = Aircraft.Rotate.z;
}
}
It changed all the values of the Sprite (x,y,z) instead of just the z.
I did also try
AircraftImage.Rotate = new Vector3(0 , 0 , Aircraft.Rotate);
and
AircraftImage.Rotate = new Vector3(0 , 0 , Aircraft.Rotate.z);
neither worked, what have I done wrong?
I don't understand your code: Aircraft and AircraftImage are GameObjects, and GameObjects don't have the Rotate method, so that code should throw an exception.
Anyway I try to help you anyway.
Try using this code:
AircraftImage.GetComponent<RectTransform>().eulerAngles = new Vector3(0, 0, Aircraft.transform.eulerAngles.z);

How to correct high volume drop off using a slider

This is my first time using a volume slider and it's the one provided from the 3D shooter tutorial on the Unity3D website. The slider works but after about the middle of the slider, the volume is already barely perceptible. It feels like it's dropping off too quickly for a slider of that size compared to sliders I'm used to, and I'm guessing there is some trig function I could use to make the dropoff smoother, but I'm not familiar enough with them yet. Does anyone know of a good way to correct this? Thanks! Here's the code I've got for it
Edit: I found this VolumeHandler script as well. I'll put it after the first one
using UnityEngine;
using System.Collections;
using UnityEngine.Audio;
public class MixLevels : MonoBehaviour {
public AudioMixer masterMixer;
public void SetSfxLvl(float sfxLvl)
{
masterMixer.SetFloat("sfxVol", sfxLvl);
}
public void SetMusicLvl (float musicLvl)
{
masterMixer.SetFloat ("musicVol", musicLvl);
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class VolumeHandler : MonoBehaviour {
// Use this for initialization
void Start ()
{
if(GameObject.Find("EffectsSlider"))
GameObject.Find("EffectsSlider").GetComponent<Slider>().onValueChanged.AddListener(SetVolume);
}
void SetVolume(float volume)
{
GetComponent<AudioSource>().volume = volume;
}
void OnDestroy()
{
if(GameObject.Find("EffectsSlider"))
GameObject.Find("EffectsSlider").GetComponent<Slider>().onValueChanged.RemoveListener(SetVolume);
}
}
If after about the middle of the slider, the volume is already barely perceptible, this means that the value in the middle should be the maximum value on the slider.
Select the Slider and change the Max Value to the value in the middle of the slider when the volume becomes barely perceptible. You can also do this from code with the Slider.maxValue property. As for smoothness, make sure that "Whole Numbers" is not enabled on the slider. If it is enabled then the slider value would be int instead of float which can cause issues.

LSPDFR Spawn Point Error

I am an LSPDFR developer and I am building a callout. I am trying to get my spawn point to spawn at a certain coordinate.
I currently have:
SpawnPoint = World.GetNextPositionOnStreet(new Vector3(-2051.99463, 3237.05835, 1456.97021));
This is in C#. I get the error Argument 1: cannot convert from 'double' to 'float'. Does anyone know what to do? And I am also writing this in Visual Studio
I have tried removing:
private Vector3 SpawnPoint;
You need to add 'J' to the end of each coordinate.
This is a very old topic, but there are no answer ..
I searched for LSPDFR -An addon for GTAV. I had hoped for a lot of activity
There was not..
Anywitch
Someone may browse for this so i will add the way to do this in LSPDFR
Firstly To get a point inside the game-world:
Press F4
In console write:
PrintInfo
Press Enter
Now you have 3 values that represent a 3Dvector
Z is UP!
Lets say we got
x:111, y:222 z:10
Script:
In your variables define a spawnpoint
public Vector3 SpawnPoint;
You can now say
SpawnPoint = new Vector3(111.0f, 222.0f, 10.0f);
and use that as a position for a object.
You can also use an object, Ped, or your player, and set a spawnpoint close by:
SpawnPoint = World.GetNextPositionOnStreet(
Game.LocalPlayer.Character.Position.Around(300f));
That will make a spawn around 300 world meters from current pos your player is in.
So that is two different ways to make a spawn-position in LSPDFR.
CODE
//will spawn a car 10 tiks from player if key J is pressed
using LSPD_First_Response;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rage;
using Rage.Native;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Engine.Scripting.Entities;
using Rage.Attributes;
[assembly: Plugin("spawn car", Description = "spawns a car", Author = "mb")]
namespace Example
{
public static class SpawnCar
{
private static void Main()
{
public Vector3 SpawnPoint;
while (true)
{
if (Game.IsKeyDown(System.Windows.Forms.Keys.J))
{
SpawnPoint = World.GetNextPositionOnStreet(
Game.LocalPlayer.Character.Position.Around(10.0f));
aaVehicle = new Vehicle("BALLER", SpawnPoint);//100 of cars are available
}
GameFiber.Yield();
}
}
}
}

Saving Data to Variable With Different Script File Unity C#

Iam confused saving data to variable with different script file.
For Example :
File player.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class player : MonoBehaviour {
public int coin = 1000;
}
File levelupstorage1raw.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
public class levelUpStorage1Raw : MonoBehaviour {
public player Player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnClickWood () {
Player.coin = Player.coin + 1000;
}
}
In this script player.cs :
public class player : MonoBehaviour {
public int coin = 1000;
}
I have inisial the coin = 1000, this mean int coin have 1000.
In Other script file levelupstorage1raw.cs :
public player Player;
// Use this for initialization
public void OnClickWood () {
Player.coin = Player.coin + 1000;
}
I have add more coin 1000 to Player.coin.
Now my question is : where the Player.coin 1000 is save ? is it save to it own file variable Player.coin or
is it save to player.cs file variable coin ?
If it save to player.cs file variable coin then variable coin now should have 2000.
You clearly have to learn a bit more about programming. Try looking for tutorials online.
Regarding your question, if I simplify things a bit to give you an idea:
A variable is something that can change. What is written in your Player.cs file is the default value, the one it will have when starting the program. When you write Player.coin = Player.coin + 1000;, the variable value changes, so Player.coin is now 2000.
At this point the first value (1000) is lost because the variable in your program has been set to 2000. But this has nothing to do with the file.
When you run your program, your file has already been transformed to a program. The file with the code is just there to tell the computer how to create the program, but it won't be modified when you run the program.
I hope this helps you understand what happens in your example. I still thing you should look for tutorials. Even basic stuff will be really difficult to achieve if you don't know the basics

Categories

Resources