In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use iTween to achieve a mouse click a place plane in the middle of a throw up and then fall of the ball, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
First, we create a plane, and we use Cube to set X and Z to 10, and then we have a terrain, and then we create a ball that needs to be generated, and then we create an empty object, put our ball under the empty object, and make it into prefabs, and then we build an icon, and here we use Cube instead of this icon, and change the color to red. We also need to create an empty object that is 0.5f away from our terrain Y, mainly to instantiate a ball in this place, and then we write a C # script on this empty object.
The code is as follows:
Using UnityEngine
Using System.Collections
Public class SphereSpawn: MonoBehaviour
{
Public GameObject spherePrefab
Public Transform redSphere
Void Update ()
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); / / get the click point on the screen
RaycastHit hitinfo
Bool isCollider = Physics.Raycast (ray, out hitinfo); / / get the point of the collision
If (isCollider & & hitinfo.collider.tag = = "Ground") {
RedSphere.position = hitinfo.point
}
If (Input.GetMouseButtonDown (0)) {
/ / instantiate the ball
SpawnSphere ()
}
}
Void SpawnSphere ()
{
GameObject go= GameObject.Instantiate (spherePrefab,transform.position,Quaternion.identity) as GameObject
Go.GetComponent () targetPosition=redSphere.position
}
}
/ / the main functions above are to determine the mouse click time (detected by X-rays) and to instantiate the ball.
And then we write a script on top of our default object, on the parent object.
Using UnityEngine
Using System.Collections
Public class MoveSphere: MonoBehaviour
{
Public Vector3 targetPosition
/ / the location you need to move to
Private GameObject sphere
Void Start ()
{
/ / Let the ball go up and down
Sphere=transform.Find ("Sphere"). GameObject
ITween.MoveTo (this.gameObject, iTween.Hash ("time", 2, "position", targetPosition, "easetype", iTween.EaseType.easeOutCubic))
ITween.FadeTo (this.gameObject, iTween.Hash ("time", 2, "delay", 2, "alpha", 0, "oncomplete", "destorySprere"))
ITween.MoveBy (sphere, iTween.Hash ("time", 1, "y", 5, "easetype", iTween.EaseType.easeOutCubic))
ITween.MoveBy (sphere, iTween.Hash ("delay", 1, "time", 1, "y",-5, "easetype", iTween.EaseType.easeInCubic))
}
Void destorySprere ()
{
Destroy (this.gameObject)
}
}
/ / the above code mainly uses iTween to instantiate how the ball moves and destroys objects.
U3D interface:
Thank you for carefully reading this article, I hope the editor shared the "how to use iTween to achieve a mouse click on a place plane in the middle of a ball thrown up and then fall" this article is helpful to everyone, but also hope that you support a lot, pay attention to the industry information channel, more related knowledge waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.