Question

In: Computer Science

Add a sphere into Unity. write ONE C# script in Unity that does the following: Set...

Add a sphere into Unity. write ONE C# script in Unity that does the following:

  1. Set the sphere to a color of your choice.

  2. Start with growing the sphere’s scale at 0.0005/frame until its scale reaches 3, then shrink

    the sphere’s scale at the same rate until it reaches 1. Repeat.

  3. Sphere rotate around the origin in XY plane at radius of 5.

position = transform.localPosition;
position.x = radius * Mathf.Sin(Time.fixedTime);
position.y = radius * Mathf.Cos(Time.fixedTime);

Solutions

Expert Solution

Answer:

//SphereBehaviour.cs:

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


public class SphereBehaviour : MonoBehaviour
{
    private float scale = 1.0f;
    private float radius = 5.0f;

    // Start is called before the first frame update
    void Start()
    {
        //sets the color of the sphere in start()
        gameObject.GetComponent<Renderer>().material.color = Color.red;
    }

    // Update is called once per frame
    void Update()
    {

        Rotate();

        if (scale >= 0 && scale <= 3)
        {
            scale += 0.0005f;
            transform.localScale += new Vector3(0.0005f, 0.0005f, 0.0005f);
        }
        else if (scale < 0)
        {
            scale += 0.0005f;
            transform.localScale -= new Vector3(0.0005f, 0.0005f, 0.0005f);
        }
        else
        {
            scale = -3;
        }

    }

    //rotates the sphere around the origin in xy plane
    void Rotate()
    {
        Vector3 position = transform.localPosition;

        position.x = radius * Mathf.Sin(Time.fixedTime);

        position.y = radius * Mathf.Cos(Time.fixedTime);

        transform.localPosition = position;

    }


}


Related Solutions

USE C# to write this. 1.To the capsule, add a script called “MoveIt”. This will make...
USE C# to write this. 1.To the capsule, add a script called “MoveIt”. This will make the capsule move repeatedly between (3, 0, 0) and (-3, 0, 0), moving 1 unit per second, moving in the positive direction initially. [Note: The capsule should move toward (3,0,0) from its initial location of (0,1,0) and then move toward (-3,0,0), etc.] 2.To the yellow cube, add a script called “RotateIt”. This will make the cube rotate (30, 60, 90) per second. 3. Lastly,...
Write an R Script that does the following for "sampleData1.dta"
Write an R Script that does the following for "sampleData1.dta" a) Regress "earn," "adcc," and "tinc" on a constant. b) Regress earnings on "higrade," "age," and "agesq." Display TSS, RSS, ESS and R Squared Value c) Reestimate the regression from pt. b, this time omitting the constant term.  
Write a script in C that will do the following : 1. Create the directory ZHW3....
Write a script in C that will do the following : 1. Create the directory ZHW3. 2. Verify that the directory is created by display all information related to the directory and not just the name of the directory. 3. Assume that the input from the command is used to validate password strength. Here are a few assumptions for the password string. • Length – minimum of 8 characters. • Contain alphabets , numbers , and @ # $ %...
Write a C++ program to calculate the sphere volume and surface area. Provided that the sphere...
Write a C++ program to calculate the sphere volume and surface area. Provided that the sphere volume = and the sphere surface area = , where r is the radius. 1. Read r from the user using cin statement. 2. Calculate the volume (Vol) and the surface area (Area) of a sphere. 3. Print r, Vol, and Area in a suitable messages.
View the following C# Script carefully. Assume that the Script is enabled, is attached to an...
View the following C# Script carefully. Assume that the Script is enabled, is attached to an active GameObject, and addresses the appropriate namespaces first. Discuss when and how often during the game the Update() function will be executed. Discuss each line (from line 9 to 17, excluding the lines with curly brackets) to detail what the code inside the update function is doing. Be sure to outline how the variables are being used during your discussion. 1 public class Player...
View the following C# Script carefully. Assume that the Script is enabled, is attached to an...
View the following C# Script carefully. Assume that the Script is enabled, is attached to an active GameObject, and addresses the appropriate namespaces first. Discuss when and how often during the game the Update() function will be executed. Discuss each line (from line 9 to 17, excluding the lines with curly brackets) to detail what the code inside the update function is doing. Be sure to outline how the variables are being used during your discussion. 1 public class Player...
Write a SQL script to add another table to your database. Include these fields in your...
Write a SQL script to add another table to your database. Include these fields in your Product table: Field Name Description Data Type Sample Value ProductID Product ID integer 5 ProductName Product Name varchar(50) candle Description Product Description varchar(255) Bee’s wax candle picUrl Filename of the product’s picture varchar(50) candle.gif Price Product Price decimal 10.99           ProductID should be the Primary Key. It is an auto-increment field.           The Price field stores prices to 7 significant digits and to 2...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a member function named      int distance2origin() that calculates the distance from the (x, y, z) point to the origin (0, 0, 0) the ‘prototype’ in the class definition will be      int distance2origin() outside the class definition             int Coord :: distance2origin() {                         // your code } _______________________________________________________________________________________________________ /************************************************** * * program name: Coord02 * Author: * date due: 10/19/20 * remarks:...
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of...
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of the default gateway on your machine (one way to get this is the 'default' entry, also shown as 0.0.0.0, in the output of 'ip route') and runs a ping (with a count of 5 pings) to it. Runs another count of 5 pings to the site example.com. Outputs a 1-line summary of interfaces on your machine, not including the loopback address (lo). Outputs a...
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT