private void Awake() { player = GameObject.Find("Player").transform; agent = GetComponent <NavMeshAgent>(); light = GameObject.Find("LightN").transform; scriptLight = light.GetComponent <LightChange>(); LightRange = scriptLight.myLight.range; }
// Start is called before the first frame update void Start() { Debug.Log("F2"); luz = GameObject.Find("LightN"); script = luz.GetComponent <LightChange>(); LuzRegenerada.Pause(); }
void Start() { afterCrashForwardPosition = 30; Lanes = GamePlayController.LanesForLaneChange; crashed = false; changeLanesSignal = false; //speed = 20f; //pt 80 km/h speed = 10f; actualTrafficCarSpeed = Mathf.Clamp(CarController.actualSpeed * 0.6f, 12, 22); //InvokeRepeating ("GetPlayerCarSpeed", 2f, 2f); //pt 150 // lane0Speed = speed * 0.38f; // lane1Speed = speed * 0.57f; // lane2Speed = speed * 0.66f; // lane3Speed = speed * 0.475f; //pt 100 lane0Speed = speed * 0.15f; lane1Speed = speed * 0.7f; lane2Speed = speed * 1.2f; lane3Speed = speed * 0.3f; int randomNumber = Random.Range(0, 5); if (randomNumber < 3) { canVariateSpeed = true; } else { canVariateSpeed = false; } //if player car is a truck, we need to increment trafficCarOvertakeOffset by 1, because the truck is wider trafficCarOvertakeOffset = 1.55f; incrementedOvertakesCounter = false; thisTrans = transform; R = Random.Range(0, 2); InitialPosition = transform.position; CarLaneLights = thisTrans.GetComponent <LightChange> (); RandomizerForLaneChange = Random.Range(1, 100); TrafficMaster = GameObject.Find("GameController"); //speedcontrol for each lane float PickedLane = thisTrans.position.x; //speed = speed / 2; OriginalSpeed = speed; if (PickedLane == Lanes[0]) { speed = lane0Speed; } if (PickedLane == Lanes[1]) { speed = lane1Speed; } if (PickedLane == Lanes[2]) { speed = lane2Speed; } if (PickedLane == Lanes[3]) { speed = lane3Speed; } #if UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 // foreach(Transform t in transform.GetComponentsInChildren<Transform>() ) // { if(t.name.Contains("Shadow") ) { // Debug.Log(t.name); // Destroy(t.gameObject); // } // } #endif gameObject.AddComponent <Rigidbody> (); GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; CheckCarType(); // Debug.Log (CustomDelimiterInterval); }
public void Start() { GetComponent<intersectionAI>().enabled= false; GetComponent<streetLight>().enabled = false; LightChanger = GetComponent<LightChange> (); }
// Update is called once per frame void Update() { if (LeftLane) { LightLeft.gameObject.SetActive(true); Target = LightLeft; LightChange T = Target.GetComponent <LightChange> (); } if (RightLane) { Target = LightRight; LightRight.gameObject.SetActive(true); LightChange T = Target.GetComponent <LightChange> (); } if (LeftLane && RightLane) { LightLeft.gameObject.SetActive(true); LightRight.gameObject.SetActive(true); Target = LightLeft; Target2 = LightRight; } // A color can have in RGB a value from 0 to 255; this renders one color unit as 1/255 float ColorUnit = 1.0f / 255.0f; //the speed with which the sine is done //if a color has been activated we will take the values of the based colors and convert them to color units //then using a Sine function we will oscilate that value between the interval give by ColoOscilator //using the OscilationFrequency in reference with Time (from -1.0f to 1.0f) //if there is no activator we will use the value of the PrimitiveRed which is by default 0 but can be changed if (LightActivator) { if (Target) { if (Red_Activator) { float ProcessedRed = (BaseRed + 60.0f) * ColorUnit; RedOscilator = 0.0f; RedWave = Mathf.Sin(Time.time * OscilationFrequency) * RedOscilator * ColorUnit; Red = ProcessedRed + RedWave; } else { Red = (PrimitiveRed - 50.0f) * ColorUnit; } if (Green_Activator) { float ProcessedGreen = (BaseGreen + 60.0f) * ColorUnit; GreenWave = Mathf.Sin(Time.time * OscilationFrequency) * GreenOscilator * ColorUnit; Green = ProcessedGreen + GreenWave; } else { Green = (PrimitiveGreen - 50.0f) * ColorUnit; } if (Blue_Activator) { float ProcessedBlue = (BaseBlue + 60.0f) * ColorUnit; BlueWave = Mathf.Sin(Time.time * OscilationFrequency) * BlueOscilator * ColorUnit; Blue = ProcessedBlue + BlueWave; } else { Blue = (PrimitiveBlue - 50.0f) * ColorUnit; } //set oscillation according to color oscilation / wave dampener float scaleOscillation = Mathf.Sin(Time.time * OscilationFrequency) / 100.0f; MultiplierPace += Time.deltaTime * 0.25f; //scale oscilation is reduced in time considering the player moving towards object float scaleMultiplier = Mathf.Lerp(3.0f, 1.5f, MultiplierPace); //create oscilatiion vector Vector3 ScaleOscilator = new Vector3(Mathf.Clamp(Target.transform.localScale.x + scaleOscillation, OriginalScale.x, OriginalScale.x * scaleMultiplier), Mathf.Clamp(Target.transform.localScale.y + scaleOscillation, OriginalScale.y, OriginalScale.y * scaleMultiplier), Mathf.Clamp(Target.transform.localScale.z + scaleOscillation, OriginalScale.z, OriginalScale.z * scaleMultiplier)); //use vector for target Target.transform.localScale = ScaleOscilator; Target.GetComponent <Renderer> ().material.color = new Color(Red, Green, Blue); if (Target2) { Target2.transform.localScale = ScaleOscilator; Target2.GetComponent <Renderer> ().material.color = new Color(Red, Green, Blue); } } } else { //reset colors to initial primitives Red = (PrimitiveRed - 50.0f) * ColorUnit; Green = (PrimitiveGreen - 50.0f) * ColorUnit; Blue = (PrimitiveBlue - 50.0f) * ColorUnit; //apply colors LightLeft.GetComponent <Renderer> ().material.color = new Color(Red, Green, Blue); LightRight.GetComponent <Renderer> ().material.color = new Color(Red, Green, Blue); //reset object scale to original LightLeft.transform.localScale = OriginalScale; LightRight.transform.localScale = OriginalScale; //deactivate object if (Application.loadedLevelName != "CarSelectionMenu") { LightLeft.gameObject.SetActive(false); } LightRight.gameObject.SetActive(false); } }